所以我从backbonejs.org的教程视频开发了一个简单的CRUD程序,代码运行正常。现在我正在尝试在requirejs中实现代码,但它在以下代码中显示以下错误: -
define([
'jquery',
'underscore',
'backbone',
'router',
'models/Customers/Customer',
'helper/Serialize'
], function ($, _, Backbone, Router, Customer, Serialize) {
var CustomerEditView = Backbone.View.extend({
el: '.page',
events: {
'submit .edit-customer-form': 'saveCustomer',
'click .delete': 'deleteCustomer',
},
saveCustomer: function (ev) {
var customerDetails = $(ev.currentTarget).serializeObject();
var customer = new Customer();
customer.save(customerDetails, {
success: function (customer) {
this.router.navigate('', { trigger: true });
}
});
return false;
},
答案 0 :(得分:1)
您可以使用:
customer.save(customerDetails, {
success: function (customer) {
Backbone.history.navigate('', { trigger: true });
}
如果你想首先使用路由器对象,你必须像
一样初始化它this.router = new router();
你可以说this.router.navigate('', { trigger: true });
在所有视图中创建新实例并不建议使对象全局化并不是最佳选择。 You can use Backbone.history.nvaigate which is alias to router.nvaigate