0
這裏是我的模型模型獲取不起作用
urlRoot: '/users',
parse: function(response) {
return response.User;
}
的身體下面是當我在瀏覽器中鍵入/users/1
什麼返回:
{"User":{"id":"1","created":"2013-02-13 09:22:42","modified":"2013-02-13 09:22:42","username":"somesuername","password":"","role":"somerole","token":null,"token_expiration":null}}
因此API的作品。 當我執行此:
this.model.id = 1;
this.model.fetch({ success: function(user){
console.log(user);
}}); // this.model is instance of my model
我得到了控制檯:
d {cid: "c4", attributes: Object, _changing: false, _previousAttributes: Object, changed: Object…}
_changing: false
_pending: false
_previousAttributes: Object
attributes: Object
__proto__: Object
changed: Object
cid: "c4"
id: Array[1]
__proto__: e
所以結果是通過模型成功並沒有取得任何數據 - 我這麼想嗎?
不 - 對不起,我粘貼控制檯輸出的格式不正確 - 擴展屬性後只有這一行'__proto__:Object'是可見的。沒有屬性 - 我知道它是如何工作的,因爲我的收藏工作正常,但型號不... – user606521 2013-02-19 17:46:18
@ user606521糟糕,沒有注意到。您是否檢查過瀏覽器開發人員工具中的響應,並確認服務器確實正在響應數據? – jevakallio 2013-02-19 17:48:37
@ user606521,有趣的是,您的模型'id'在檢查器中是'Array [1]'。不知道怎麼會出現這種情況,但我很確定這與你的問題有關。 – jevakallio 2013-02-19 17:51:58