私はしばらくこれに苦労してきましたが、机に頭をぶつけ続けるのではなく、諦めてここで質問しようと思いました. これはかなり基本的なものです。バックボーンから始めたばかりです。.get() 関数を介して person にアクセスできないのはなぜですか?
私はajax コードにMockjaxを使用しています。これは次のようになります。
$.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'
バックボーン正午の助けをいただければ幸いです。