backbone.jsモデル
-
29-10-2019 - |
質問
ここで完全に間違ったことをしていますか?私はJSONP応答からバックボーンモデルに浸透しています。 FireBugで最初のコンソールステートメントを表示すると、「現在」のオブジェクトには属性の下に「アイコン」があります。ただし、印刷するとき console.log(current.has("icon"))
falseを返し、したがってcurrent.get( "アイコン")は未定義に戻ります。
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
正しい解決策はありません
所属していません StackOverflow