无法访问Dojo JsonRest存储中的数据,目标是PHP


Unable to access data in Dojo JsonRest store, target is PHP

我正在尝试复制结果。dojotoolkit.org的dojo/Store/jsonRest (v1.8)参考指南中的示例。

我的jsonRest存储目标是一个php页面,因为我在这里了解到,我添加了console.debug(data);,在firebug中显示数据是从php返回的方式,我认为应该是:(对不起,试图在这里显示图片,但我不能)

问题是我不知道如何访问这些数据。results.total.then没有返回任何东西,我认为这个函数甚至没有运行。

我尝试了store.get,这给了我一个404错误的php url。我试着像这样转换商店:newStore = ObjectStore({objectStore: store});,然后在newStore上运行查询,这没有错误,但也没有结果。

我也得到一个404错误,如果我尝试使用"foo=bar"语法查询商店,在我的情况下store.query ("ADDNUM='200'"),但没有错误,如果我使用store.query ({ADDNUM:"200"})语法。

我的最终目标是让结果显示在dojo filteringselect中,但现在我将满足于能够得到它们,甚至只是console.log(result)。
非常感谢任何人可以给予的任何帮助!

require([
  "dojo/store/JsonRest", 
  "dojo/data/ObjectStore", 
  "dojo/store/Memory"
  ], function(JsonRest, Memory, ObjectStore){
    var store = new JsonRest({
    target: "scripts/AddressNumTest.php"
    });
var self = this;
var results = store.query({ADDNUM:"200"}).then(function(data){
  console.debug(data);  //results from this look okay to me
  results.total.then(function(total){
     console.log("Never gets here??");
     console.log("total results: ", total);
     console.log("go on and use data ", data, " with this ", self);
     });
  });
//store.query("ADDNUM='200'")  //this returns 404 error
//below gives 404 error           
//var results2 = store.get({ADDNUM:"200"}).then(function(newdata){
//console.log("from get: " + newdata);            
//});
});

Result when no Error but also no success in accessing data in store: GET ../scripts/AddressNumTest.php?ADDNUM=200 200 OK -- RESPONSE: {identifier: 'OBJECTID', label: 'ADDNUM', 'items':[{"ADDNUM":"136","OBJECTID":"307"},{"ADDNUM":"150","OBJECTID":"308"},{"ADDNUM":"200","OBJECTID":"8494"},{"ADDNUM":"210","OBJECTID":"8495"},{"ADDNUM":"220","OBJECTID":"2950"}]}

404 Error when using store.get: GET .../scripts/AddressNumTest.php%5Bobject%20Object%5D 404 Not Found RequestError: Unable to load scripts/AddressNumTest.php[object Object] status: 404

404 Error when I use "ADDNUM='200'" syntax: GET .../scripts/AddressNumTest.phpADDNUM=%27200%27 404 Not Found RequestError: Unable to load scripts/AddressNumTest.phpADDNUM='200' status: 404

我不知道结果是否在闭包中可用,但我认为您不需要它。回调是在data中传递的,这在你的console.debug(data)中看起来是正确的,所以让我建议这个代码。

var results = store.query({ADDNUM:"200"}).then(function(data){
  console.debug(data);  //results from this look okay to me
  console.log("You will get here!  :)");
  // I do not know what data looks like so this may or may not work.
  console.log("total results: ", data.total);
  console.log("go on and use data ", data, " with this ", self);
});