define(["jquery" ,
"underscore" ,
"backbone" ,
"custom",
"wishlist"
],function($ , _ , Backbone, Ice, WishList){
var wishlist1 = new WishList();
var SavedCartView = Backbone.View.extend({
tagName:"div",
initialize : function(){
console.log("hi!");
},
event : {
'click .savedCart' : 'viewEachCart'
},
viewEachCart : function(e){
console.log(1);
},
render : function(){
wishlist1.viewAllSaveCart(106,function(output){
_.each(output,function(row){
$("#webbodycontainer").append('<a class="savedCart" id="'+row.ID+'">'+row.Name + "</a><br>");
});
});
}
});
return SavedCartView;
});
这是路由器:
app_router.on('route:savedCart', function( ){
if(window.currentSection)
window.currentSection.remove();
window.currentSection = new SavedCart({});
$("#webbodycontainer").html(window.currentSection.$el);
window.currentSection.render();
});
console.log(1);
不起作用,不知道是什么导致了这一点。感谢。
答案 0 :(得分:0)
我认为这应该是events : {
答案 1 :(得分:0)
如果“.savedCart”是锚标记(如下所示):
<a href="" class="savedCart">Saved Cart</a>
...然后你需要在你的函数中使用e.preventDefault(),这样就不会激活链接。
events : {
'click a.savedCart' : 'viewEachCart'
},
viewEachCart : function(e){
e.preventDefault();
console.log(1);
},