백본 js를 읽는 데 새로운 사람이고 에 심각한 문제가 있습니다.인수을 백본 js에 전달합니다. 당신은 내가이 기능이 볼 수백본 js 전달 인수
var Song = Backbone.Model.extend();
var Songs = Backbone.Collection.extend({
model: Song
});
var SongView = Backbone.View.extend({
el: "li",
render: function() {
this.$el.html(this.model.get("title"));
return this;
}
});
var SongsView = Backbone.View.extend({
el: "ul",
initialize: function() {
this.model.on("add", this.onSongAdded, this);
},
onSongAdded: function(song) { // when object is added to a collection add event is triggerd
// the handler for this event get an argument which is the object that was just added
//in this case it refers to a song model so we simply pass it to our songView which is responsible for rendering a song an then we use jquery append method
// to append it to our list
var songView = new SongView({
model: Song
});
this.$el.append(songView.render().$el);
},
render: function() {
var self = this;
this.model.each(function(song) { //
var songView = new SongView({
model: Song
});
self.$el.append(songView.render().$el);
});
}
});
var songs = new Songs([
new Song({
title: "1"
}),
new Song({
title: "2"
}),
new Song({
title: "3"
})
]);
var song_1 = new Song({
title: "hello"
});
var songsView = new SongsView({
el: "#songs",
model: Songs
});
songsView.render();
: 이 onSongAdded 일부 내장과 같이 3 개 인수를 얻을 같은 추가 등의 이벤트 우리는이 : 추가 (컬렉션, 모델, 옵션) 내가 어떻게 할 수 내 코드에서이 인수를 사용합니까? 나를 도와 줄 수 있습니까?
감사합니다. –