モデルの todo アイテムを TodoListView から TodoView に渡したいです。しかし、それはできません。私のコードはこのようなものです。
define(["jquery","underscore","backbone","todo_view","todo"],
function($,_,Backbone,TodoView,Todo){
var TodoListview = Backbone.View.extend({
tagName: "ul",
initialize:function(){
_.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
_.bindAll(this,"addTodo","render");
this.collection.bind("add",this.addTodo,this);
this.collection.bind("reset",this.render,this);
},
render:function(){
this.$el.empty();
this.collection.each(this.addTodo);
return this;
},
addTodo:function(item){
console.log(item.get("title"));
// it's works correctly -> Backbone.model
var todoView = new TodoView({model:item});
var str = todoView.render().$el;
this.$el.append(str);
}
});
return TodoListview;
});
// todo_view.js
define(["backbone","underscore"],function(Backbone,_){
var TodoView = Backbone.View.extend({
tagName: "li",
template: "#todo-view-template",
events: {
"click .done": "toggleDone"
},
initialize:function(){
_.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
this.render();
},
render:function(){
var str = $(this.template).html();
var template = _.template(str,{name: "hello"});
console.log(this.model) //#-> Backbone.Model.
console.log(this.model.get("title")
//#-> undefined get method. why??
return this;
},
toggleDone:function(){
}
});
return TodoView;
});
TodoView の this.model.get("title") メソッドが undefined を出力する理由がわかりません。何か考えはありますか?よろしくお願いします。