Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在RESTful服务中使用JsonRestStore_Javascript_Dojo - Fatal编程技术网

Javascript 如何在RESTful服务中使用JsonRestStore

Javascript 如何在RESTful服务中使用JsonRestStore,javascript,dojo,Javascript,Dojo,我尝试在RESTful服务中使用dojox.data.JsonRestStore。我阅读了sitepen和dojox文档中的文章,但我不明白它们都是关于什么的。 我的服务收到如下请求http:///rest/relatedsuggestion?query=weath&results=3 并返回JSON { Suggestions: [ “weather channel”, “weather forecast”, “weather bbc” ] } 这意味着它无法

我尝试在RESTful服务中使用dojox.data.JsonRestStore。我阅读了sitepen和dojox文档中的文章,但我不明白它们都是关于什么的。 我的服务收到如下请求http:///rest/relatedsuggestion?query=weath&results=3 并返回JSON

{
Suggestions: [
    “weather channel”,
    “weather forecast”,
    “weather bbc”
    ]
}
这意味着它无法理解这样的请求http:///rest/relatedsuggestion/3 在每个教程中都会用到。我怎样才能理解我的格式?据我所知,这种反应对这门课来说也是不寻常的

为了尝试JsonRestStore,我编写了以下模拟页面,当然它不工作,并返回4个错误类型error:_57为null:

<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>

这篇IBM developerWorks文章可能会有所帮助:


根据您的描述,您的服务是非标准的,因此您需要调整URL和响应混乱,以符合JsonRestStore的期望。这篇文章解释了如何通过实现自己的服务来实现这一点。

Hi Kirill,如果我错了,请纠正我,我认为获取是异步的。因此poStore.fetchItemByIdentity代码应该在dojox.data.JsonRestStore的oncmlete方法中。我不知道这一点,但文档中没有这样的事件,有onDelete、onNew、start