을 backbone.js : "catch되지 않은 구문 에러 : 예기치 않은 토큰",간단한 이벤트는, 내가 오류 다음 얻을 index.html을에서이를 실행에 오류
events: {
"click #add-friend": "showPrompt",
},
를 참조 그것은 특별히을 의미한다 ":"여기 "click # add-friend": "showPrompt" 아래의 추가 컨텍스트. 어떤 조언을 주시면 감사하겠습니다.
(function ($) {
Friend = Backbone.Model.extend({
// create a model to to hold friend attribute
name: null
});
Friends = Backbone.Collection.extend({
// this is our friends collection and holds out Friend models
initialize: function(models, options) {
this.bind("add", options.view.addFriendLi);
// listens for "add" and calls a view function if so
}
});
AppView = Backbone.View.extend({
el: $("body"),
initialize: function() {
this.friends = new Friends(null, {view: this});
// creates a new friends collection when the view is initialized
// pass it a reference to the view to create a connection between the two
events: {
"click #add-friend": "showPrompt"
},
showPrompt: function() {
var friend_name = prompt("Who is your friend?");
var friend_model = new Friend({name:friend_name});
// adds a new friend model to out Friend collection
this.friends.add(friend_model);
},
addFriendLi: function (model) {
// the parameter passed is a reference to the model that was added
$("#friends_list").append("<li>" + model.get('name') + "</li>");
}
});
var appview = new AppView;
})(jQuery);
쉼표 제거가 도움이되지 않았습니다. – zallarak
수정 해 주셔서 감사합니다! – zallarak