別のビューから渡した既存のモデルのランク属性を更新したかったのです。ただし、エラーUncaught TypeError:Object#has nomethod'set'が表示されます。
ビューの初期化部分には、次のものがあります。
this.collection = new tgcollection({model : this.options.model });
属性値を更新することを目的とした関数updateModelを次のように定義します。
updateModel: function(){
var val= $("#textbox_id").val();
console.log(val);
console.log(JSON.stringify(this.options.model));
JSON.stringify(this.options.model);
this.options.model.set({"rank": val});
this.render();
//
},
どこが間違っているのですか?値と以前の属性値を持つモデルをコンソールで確認できます。
モデル:
define(['jquery','underscore', 'backbone', 'deepmodel'],
function($,_, Backbone) {
var model = Backbone.DeepModel.extend({
// Default attributes for the model.
defaults : {
id: null,
rank: null,
},
initialize: function(){
_.bindAll(this,"update");
this.bind('change : cost', this.update);
},
update: function(){
console.log(this.get("cost"));
},
// Remove this model from *localStorage*.
clear : function() {
this.destroy();
},
});
return model;
});