【问题标题】:Unable to access data in Dojo JsonRest store, target is PHP无法访问 Dojo JsonRest 存储中的数据,目标是 PHP
【发布时间】:2013-03-28 22:38:27
【问题描述】:

我正在尝试从 dojotoolkit.org 的 dojo/Store/jsonRest (v1.8) from here 参考指南中复制 results.total 示例。

我的 jsonRest 存储目标是一个 php 页面 as I learned about here,我添加了 console.debug(data);,它在 firebug 中显示数据以我认为应该的方式从 php 返回:(抱歉试图在这里显示图片,但我可以't)

问题是我不知道如何访问数据? results.total.then 没有返回任何内容,我认为该函数甚至不会运行。

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

如果我尝试使用“foo=bar”语法(在我的情况下为 store.query ("ADDNUM='200'"))查询商店,也会收到 404 错误,但如果我使用 store.query ({ADDNUM:"200"}) 语法,则不会出现错误。

我的最终目标是让结果显示在 dojo 过滤选择中,但现在我会满足于能够得到它们,即使只是 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

【问题讨论】:

    标签: php json dojo


    【解决方案1】:

    我不知道结果是否在闭包中可用,但我认为您不需要它。回调传入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);
    });
    

    【讨论】:

    • @uog 让我知道这是否有帮助。如果您无法发表评论,您可以编辑问题。
    • 非常感谢!直到现在我都无法对其进行测试并且仍然有一些问题,但是是的,data 确实保存了从 php 返回的 json。 data.total 以未定义的形式返回,但我实际上并不需要总数。我的 filterselect 从来没有用过,所以我想确定商店里真的有东西。现在我将回到filterselect问题...相关的问题,也许你知道,既然查询是针对一个特定的值(“200”),为什么dataall返回的json?
    • 对不起,我不知道为什么它会返回所有行。
    猜你喜欢
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    相关资源
    最近更新 更多