我有一个包含多个按钮的视图来执行不同的操作。
var HomeView = Backbone.View.extend({
initialize: function() {
},
events : {
'click #addToWL' : 'addWishList'
},
addWishList : function(){
var _wishList = new WishList();
_wishList.set({
"ID" : 0,
"Name" : "",
"CustomerID" : 106,
"Type" : 0,
"LastUpdated" : "\/Date(1383152400000+0700)\/",
"WishlistDetail" : [
{
"ID" : 0,
"WishListID" : 0,
"ItemID" : 22776,
"Quantity" : 2,
"LastUpdated" : "\/Date(1383152400000+0700)\/"
}
]
});
_wishList.save();
var _wlView = new WishListView({model:_wishList});
},
render : function(){
this.$el.html(homePanel);
$("#containernewpromotion").html(promotionItem);
}
});
return HomeView;
这是另一个文件中的 WishList 视图:
var WishList = Backbone.View.extend({
tagName: 'ul',
initialize:function(){
console.log("initialize wish list view");
},
render: function(){
this.$el.empty();
var wishlistView = _.template(WishListTemplate);
this.$el.append(wishlistView);
}
});
return WishList;
这是愿望清单模型:
define(["underscore" , "backbone"],function(_ , Backbone){
var WishList = Backbone.Model.extend({
url :'//path to REST AddWishList',
idAttribute: 'ID'
});
var _wishList = new WishList();
_wishList.set({
"ID" : 0,
"Name" : "",
"CustomerID" : 106,
"Type" : 0,
"LastUpdated" : "\/Date(1383152400000+0700)\/",
"WishlistDetail" : [
{
"ID" : 0,
"WishListID" : 0,
"ItemID" : 22776,
"Quantity" : 2,
"LastUpdated" : "\/Date(1383152400000+0700)\/"
}
]
});
_wishList.save();
return WishList;
});
当我单击 中的
#addToWL
按钮时HomeView
,视图中的initialize
功能WishList
正在运行,但addWishList
功能没有。当我点击in时,如何调用
WishList
模型来执行。#addToWL
HomeView
我刚从 Backbone.js 开始,非常感谢任何帮助。谢谢。