【发布时间】:2015-12-08 14:55:18
【问题描述】:
我在点击事件保存模型后尝试切换视图时遇到问题。
我尝试创建的流程是一个重新订购流程,用户将有一个确认页面来重新订购。单击提交后,将执行 api 调用,成功后将加载发票页面。
目前,当我第一次单击提交按钮时没有任何反应,当我再次单击时,我可以获得发票页面。取消按钮没有这样的问题。
var confirmView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
var template = _.template( $("#confirmReorder_template").html());
this.$el.html(template);
},
events: {
"click #submitButton": "submitReorder",
"click #cancelButton": "cancelReorder"
},
submitReorder: function(event){
var URI='<config property="api.url.itemReorder"/>';
var ItemReorderModel = new itemReorderModel({url:URI});
$("#submitButton").click(function(event) {
event.preventDefault();
ItemReorderModel.set('id','1');
ItemReorderModel.save( {}, {
success : function() {
var response = ItemReorderModel.toJSON();
var InvoiceView = new invoiceView({el: $("#itemData")});
},
error : function(model, xhr, options) {
}
});
});
},
cancelReorder: function(event){
document.location.href = "items_list.ctl";
}
});
第二个视图
var invoiceView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
var template = _.template( $("#reorderInvoice_template").html());
this.$el.html(template);
},
events: {
"click #returnButton": "itemlist",
"click #printButton": "print"
},
itemlist: function(event){
document.location.href = "items_list.ctl";
},
print: function(event){
}
});
加载第一个视图
$(document).ready(function() {
var ConfirmView = new confirmView({el:$('#itemData')});
});
我是骨干网的新手,所以不确定是否应该使用路由,我也读过一些关于绑定的文章,但仍在努力了解它是如何工作的。
非常感谢任何建议。
【问题讨论】:
标签: javascript jquery backbone.js