toJSON()
モデルを返して編集する の機能のような機能を持つ関数を作りたいです。
私の質問は、モデルの属性を反復し、選択した属性の特定の値を編集する方法です。
モデルがある場合:
Item = Backbone.Model.extend({
defaults: {
name: '',
amount: 0.00
},
toHTML: function(){
// i think this is the place where
// where i can do that function?
//
console.log(this.attribute)
}
});
var item = new Item;
item.set({name: 'Pencil', amount: 5}):
item.toJSON();
-> {name: 'Pencil', amount: 5}
// this is the function
item.toHTML();
-> {name: 'Pencil', amount: 5.00}