我一直在爲這個問題苦苦掙扎了一陣子,並且以爲我只會放棄並問問這裏,而不是繼續將我的頭撞向我的桌子。這是非常基本的東西,我只是從骨幹開始。爲什麼我不能通過.get()函數訪問人員?。主題中的get()問題
我使用Mockjax我的Ajax代碼和看起來像這樣:
$.mockjax({
url: '/data',
contentType: 'text/json',
responseTime: 150,
type: 'GET',
responseText: '[{ "name": "Chance, Churc", "id_number": "", "w_time": null, "o_time": null }]'
});
和骨幹部分:
var PWItem = Backbone.Model.extend({});
var person = new PWItem();
person.fetch({
url: '/data',
success: function() {
console.log(person.attributes[0].name); //this prints the correct attribute
}
}):
console.log(person); //prints the person object
console.log(person.get('name')); //prints 'undefined'
爲骨幹中午任何幫助,將不勝感激。
取是異步的,所以你需要把在執行console.log一個函數,然後調用該函數時,成功處理程序觸發 – Matt 2013-03-06 21:24:53