0
在這裏我的問題,我想動態地改變我的模型(當集合被實例化時,動態地改變我模型中的變量)。動態改變骨幹模型
所以在這裏我的代碼:
define(['backbone'], function (backbone) {
var MyModel = Backbone.Model.extend({
initialize: function() {
var that = this;
var likes;
var UrlGetLike = "https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27https://www.facebook.com/pages/Stackoverflow/1462865420609264%27&format=json";
$.getJSON(UrlGetLike, {
format: "json"
})
.done(function(data) {
likes = data[0].like_count;
that.set({
'likes' : likes
});
});
},
});
return MyModel;
});
但不更新數據,爲MyModel是中,.done前()返回結束..
我試試這個太:
define(['backbone'], function (backbone) {
var MyModel = Backbone.Model.extend({
initialize: function() {
var that = this;
var likes;
var UrlGetLike = "https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27https://www.facebook.com/pages/Stackoverflow/1462865420609264%27&format=json";
$.getJSON(UrlGetLike, {
format: "json"
})
.done(function(data) {
likes = data[0].like_count;
that.set({
'likes' : likes
});
that.returnn;
});
},
returnn: function(){
return this;
}
});
});
但我得到這個錯誤無法讀取未定義的屬性'原型',因爲我解僱了
var collection = new Collection({collection : MyModel});
之前MyModel是返回(我認爲)
如果任何人有解決方案或東西來幫助我,它將不勝感激:)。
那麼,你是否解決了你的問題? – Mironor 2014-11-03 06:42:24