I가 나는 다음과 같은 오류 얻을 코드를 다시 실행되었을 때 내가 어제 그러나 오늘 작업 한 다음 다음 코드를 catch되지 않은 ReferenceError가 : tasksCollection가 정의되어 있지를catch되지 않은 ReferenceError가 백본 JS
(function(){
window.App={
Models:{},
Collections:{},
Views:{}
};
window.template=function(id){
return _.template($('#' +id).html());
};
App.Models.Task=Backbone.Model.extend({});
App.Collections.Tasks=Backbone.Collection.extend({
model:App.Models.Task
});
App.Views.Task=Backbone.View.extend({
tagName:'li',
template:template('taskTemplate'),
initialize:function(){
//when model change it will change !
//this.model.on('change',this.render,this);
this.render();
},
events:{
'click .edit':'editTask',
'click .delete':'deleteTask'
},
editTask:function(){
var newTitle = prompt('what would you like to be your title?',this.model.get('title'));
this.model.set('title',newTitle);
},
deleteTask:function(){
alert('delete');
},
render:function(){
var template= this.template(this.model.toJSON());
this.$el.html(template);
return this;
}
});
App.Views.Tasks=Backbone.View.extend({
tagName:'ul',
initialize:function(){
this.render();
},
render:function(){
this.collection.each(this.addOne,this);
return this;
},
addOne:function(task){
//creat new child view
var taskView= new App.Views.Task({ model:task});
taskView.render();
//append to the root element
this.$el.append(taskView.render().el);
}
});
var tasksCollection=new App.Collections.Tasks([
{
title:'Hi',
name:'samin'
},
{
title:'Hi',
name:'nazanin'
},
{
title:'Baby',
name:'nazanin'
}
]);
var tasksView=new App.Views.Tasks({collection:tasksCollection});
console.log(tasksView.el);
$('.tasks').html(tasksView.el);
})();
오류를 해결할 수 없습니다. 모든 것이 잘 작동해야하는 것처럼 보입니다. 여러분이 저를 도와 주실 수 있습니까 ?? 나는 그것을 밖으로 그림 몇 가지 조사이 방법
후
당신은 당신의 마크 업을 게시하시기 바랍니다 수 (을 TaskTemplate 및 HTML)뿐만 아니라? – lucasjackson
오류 스택 추적을 게시하십시오. – Louis