Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 无法读取属性';更换';未定义BackboneJS的_Backbone.js_Requirejs - Fatal编程技术网

Backbone.js 无法读取属性';更换';未定义BackboneJS的

Backbone.js 无法读取属性';更换';未定义BackboneJS的,backbone.js,requirejs,Backbone.js,Requirejs,我正在尝试使用模块化BackboneJS渲染视图(CustomerEdit视图),但它给了我未捕获类型的错误 这是我的router.js文件: define([ 'jquery', 'underscore', 'backbone', 'views/Customers/CustomerEditView', 'views/Customers/CustomerListView' ], function($, _, Backbone, CustomerEditView, CustomerListView

我正在尝试使用模块化BackboneJS渲染视图(CustomerEdit视图),但它给了我未捕获类型的错误

这是我的router.js文件:

define([
'jquery',
'underscore',
'backbone',
'views/Customers/CustomerEditView',
'views/Customers/CustomerListView'
], function($, _, Backbone, CustomerEditView, CustomerListView) {

    var Router = Backbone.Router.extend({
        routes: {
            "customers": "customerhome",
            "editcustomer/:id": "editcustomer",
            "newcustomer": "editcustomer",
        },

        customerhome: function () {
            var customerListView = new CustomerListView();
            customerListView.render();
        },

        editcustomer: function (id) {
            var customerEditView = new CustomerEditView();
            customerEditView.render({ id: id });
        }
    });

    var initialize = function () {

        var router = new Router;
        Backbone.history.start();

    };

    return {
        initialize: initialize
    };
});
这是我的CustomerEdit文件:

define([
'jquery',
'underscore',
'backbone',
'router',
'models/Customers/Customer',
'helper/Serialize',
'text!template/Customer/CustomerEditTemplate.html'
], function ($, _, Backbone, router, Customer, Router, serializeObject, CustomerEditTemplate) {

    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) {
                    Backbone.history.navigate('', { trigger: true });
                }
            });
            return false;
        },
        deleteCustomer: function (ev) {
            this.customer.destroy({
                success: function () {
                    console.log('destroyed');
                    Backbone.history.navigate('', { trigger: true });
                }
            });
            return false;
        },
        render: function (options) {
            var that = this;
            if (options.id) {
                that.customer = new Customer({ id: options.id });
                that.customer.fetch({
                    success: function (customer) {
                        var template = _.template(CustomerEditTemplate);
                        that.$el.html(template({ customer: customer }));
                    }
                });
            } else {
                var template = _.template(CustomerEditTemplate);
                that.$el.html(template({ customer: null }));
            }
        }
    });

    return CustomerEditView;
});

哪一行导致错误?var template=u.template(CustomerEditTemplate);谢谢你的帮助。我从辩论中删除了路由器。代码现在运行。非常感谢