0

我收到以下错误

uncaught exception: Please include Backbone.ModelBinder.js before Backbone.CollectionBinder.js

做完之后

node r.js -o build.js

我的 build.js 文件是

({    
    "mainConfigFile": 'js/main.js',
    "name": "main", 
    "include": [
        "lib/require/require-with-comments.js"
    ], 
    "exclude": [], 
    "optimize": "uglify2", 
    "out": "main-built.js", 
    "insertRequire": [
        "js/main"
    ]
})

我的要求配置如下

require.config({
    // The shim config allows us to configure dependencies for
    // scripts that do not call define() to register a module
    urlArgs: "bust=" + (new Date()).getTime(),    
    shim: {
        'underscore': {
            exports: '_'
        },
        'bootstrap': {
            deps: [
                'jquery'
            ]
        },
        'backbone': {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        }, 'handlebars': {
            exports: 'Handlebars'
        }, 'handlebarsview': {
            deps: [
                'backbone',
                'handlebars'
            ],
            exports: 'HandlebarsView'
        }, 'highcharts': {
            deps: [
                'jquery'
            ],
            exports: 'highcharts'
        }
        , 'collectionbinderview': {
            deps: [
                'backbone',
                'jquery',
                'underscore',
                'modelbinderview'
            ]
        }, 'purl' : {
            deps : ['jquery']
        }
        , 'select2': {
            deps: [
                'jquery'
            ],
            exports: 'select2'
        }
        , 'customSelect': {
            deps: [
                'jquery'
            ],
            exports: 'customSelect'
        }
        , 'datepicker': {
            deps: [
                'jquery',
                'momentjs'
            ],
            exports: 'datepicker'
        }
    },
    paths: {
        jquery: 'lib/jquery/jquery.min',
        bootstrap: 'lib/bootstrap/bootstrap',
        underscore: 'lib/lodash/lodash.min',
        backbone: 'lib/backbone/backbone',
        text: 'lib/require/text',
        handlebars: 'lib/view/hacked-handlebars-1.0.0',
        handlebarsview: 'lib/view/backbone.handlebars',
        collectionbinderview: 'lib/view/Backbone.CollectionBinder',
        modelbinderview: 'lib/view/Backbone.ModelBinder',        
        highcharts: 'lib/charting/highcharts',
        momentjs: 'lib/view/moment',
        select2: 'lib/select2/select2',
        customSelect: 'lib/customSelect/customSelect',
        datepicker: 'lib/view/datepicker',
        purl : 'lib/purl/purl'
    }
});

谁能告诉我我做错了什么?

4

2 回答 2

0

collectionbinderview:'lib/view/Backbone.CollectionBinder',modelbinderview:'lib/view/Backbone.ModelBinder',

尝试切换它们。将 ModelBinder 放在 CollectionBinder 之前。

于 2013-09-17T12:17:24.140 回答
0

出现此问题是因为 CollectionBinder 在加载后立即执行,而 ModelBinder 是 AMD,因此尚未定义。简而言之,CollectionBinder 不是 AMD 库。

我从以下问题得到了上述解决方案:
https://github.com/theironcook/Backbone.ModelBinder/pull/111
并且提交是 https://github.com/rweng/Backbone.ModelBinder/commit/9e93e7c9236ccef71c87a3dc4023910f9ac03803

于 2013-09-18T03:19:51.243 回答