2011-06-14 38 views
1

我尝试使用dojox.data.JsonRestStore和我的RESTful服务。我通过sitepen和dojox文档阅读文章,但我无法理解它们的含义。 我的服务变得像http://<host>/rest/relatedsuggestion?query=weath&results=3请求并返回JSON如何在我的RESTful服务中使用JsonRestStore

{ 
Suggestions: [ 
    “weather channel”, 
    “weather forecast”, 
    “weather bbc” 
    ] 
} 

这意味着它无法理解像http://<host>/rest/relatedsuggestion/3这是在每一个教程中使用的要求。我怎样才能让它理解我的格式?据我所知,这个课程的答案也是不寻常的。

为了尽量JsonRestStore我写了下面模拟了网页,五言它不工作,返回4个错误“错误类型:_57为空”:

<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js" 
    djConfig="parseOnLoad: true"> 
    </script> 
    <script type="text/javascript"> 
     dojo.require("dojox.data.JsonRestStore"); 
     dojo.require("dojox.grid.DataGrid"); 

     dojo.addOnLoad(function() { 
      var poStore = new dojox.data.JsonRestStore({target:"http://<host>/rest/features/relatedsuggestion"}); 

      poStore.fetchItemByIdentity({ 
       identity:"3433", 
       onItem:function(poItem){ 
        poItem.completeOrder(); 
       } 
      }); 
     }); 
    </script> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" 
    /> 
</head> 

<body class=" claro "> 
    <div id="gridElement"></div> 
</body> 
+0

嗨基里尔,纠正我,如果我错了,我认为这是一个异步。所以poStore.fetchItemByIdentity代码应该在dojox.data.JsonRestStore的onComlete方法中。 – rajkamal 2011-06-15 06:58:34

+0

我不知道,但文档中没有这样的事件(有onDelete,onNew,onSet) – 2011-06-15 08:51:40

回答

0

这个IBM developerWorks文章可能是帮助:Use Dojo's JsonRestStore with your REST services

从您的描述来看,您的服务是非标准的,因此您需要对网址和响应进行调整以适应JsonRestStore的期望。该文章解释了如何通过实施自己的服务来实现这一点。