我在這裏做的事情完全錯誤嗎?我從jsonp響應中填充骨幹模型。當我在firebug中查看第一個控制檯語句時,「當前」對象在屬性下具有「圖標」。但是,在打印console.log(current.has("icon"))
時,它返回false,因此current.get(「icon」)將返回undefined。Backbone.js模型
var Current = Backbone.Model.extend({
url: "A_valid_url",
sync: function(method, model, options) {
options.timeout = 10000;
options.dataType = "jsonp";
return Backbone.sync(method, model, options);
},
parse: function(response, xhr) {
return response.current_observation;
}
});
var current = new Current({test: "blah"});
current.fetch();
console.log(current);//under attributes there is a "icon"
console.log(current.has("icon")); //false
console.log(current.get("icon")); //undefined
console.log(current.has("test")); //true
grr我知道這是愚蠢和簡單的事情。謝謝! – flynfish 2012-01-18 02:04:46
太棒了 - 很高興它有幫助 – timDunham 2012-01-18 02:08:37