I have one view ( HomeView
) render template using text! plugin. This is Home view :
var HomeView = Backbone.View.extend({
initialize: function() {
myCart.updateQtyLabel("qtyCart");
},
el: '#webbodycontainer',
events : {
"click #addToCart" : function(){
myCart.addToCart(newItem);
myCart.updateQtyLabel("qtyCart");
$("#containernewpromotion").html(promotionItem);
}
},
render : function(){
this.$el.html(homePanel);
$("#containernewpromotion").html(promotionItem);
}
});
This is html template :
<% var items = deserializeJSONToObj(localStorage.getItem("Cart"));%>
<% if(items != null){ %>
<% var i = 0; %>
<% _.each(items, function(item) { %>
<% if (i < 4){ i++; } else { return false; }%>
<div class="promotionColumn">
<div class="itemImg">
<a href="#itemDetail"><img src="<%=WebConfig.PartImageBrand + item.PictureName%>" width="135px"/></a>
</div>
</div>
<% }); %>
<% } %>
This is itemDetail
view :
var ItemDetailView = Backbone.View.extend({
initialize: function() {
alert("test");
},
render: function(){
alert("test2");
}
});
When I click on <a href="#itemDetail">
, I got a warning message in chrome console event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
, and alert
in ItemDetailView
is not working.
The url goes /#itemDetail
but the template used in HomeView
still displayed in itemDetail
router. HomeView
content is dropped from itemDetail
page when I press refresh
in my browser.
Any idea what could be causing this please. Thanks.
The events object in a backbone view is of the following structure
"events" : {
"event selector" : "handler"
},
"handler" : function(){
}
The value in the events object is a string, not a function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.