Jquery getJson不使用php json_encode

时间:2014-10-08 20:46:23

标签: javascript php jquery ember.js

以下是php json_encode输出示例

{"user_id":34543456532,"user_status":true,"name":"ABC","propic":"http:\/\/pbs.twimg.com\/profile_images\/....."}

我正在使用ember,所以Route是

  model: function(params) {
    return Em.RSVP.hash({
      uposts: tweets,
      ustat: [$.getJSON( "status.php")]
    });
  }

处理此问题的HTML / Handlebars代码是

{{#if ustat.[0].user_status}}
do something
{{else}}
do something else
{{/if}}

然而, user_status 总是返回false,当我使用某些虚拟值时,如

  model: function(params) {
    return Em.RSVP.hash({
      uposts: tweets,
      ustat: [{"user_id":34543456532,"user_status":true,"name":"ABC","propic":"http:\/\/pbs.twimg.com\/profile_images\/....."}]
    });
  }

它工作正常,错误在哪里,我该如何解决?谢谢

1 个答案:

答案 0 :(得分:0)

$.getJSON不会从调用中返回数据,而是返回一个promise。也许这样的事情会更好:

$.getJSON( "status.php").then(function(statusData){
   ...
   model: function(params) {
    return Em.RSVP.hash({
      uposts: tweets,
      ustat: [statusData]
    });
   }
   ...
});
相关问题