繁体   English   中英

使用requirejs加载主干插件

[英]loading backbone plugins with requirejs

我想知道如何用require.js加载主干插件,目前我的main.js中有这个插件

(function() {
    'use strict';

    require.config({
    shim: {
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        },
        deepModel: {
            deps: ['underscore', 'backbone']
        }
    },
    paths: {
        jquery: 'lib/jquery/jquery',
        underscore: 'lib/underscore/underscore',
        backbone: 'lib/backbone/backbone',
        text: 'lib/requirejs-text/text',
        deepModel: 'lib/deep-model/deep-model.min'
    },

在我的模型中,我有这样的东西

var myapp = myapp|| {};
(function() {
    'use strict';

    define([
    'jquery',
    'underscore',
    'backbone',
    'deepModel',
    ], function($, _, Backbone) {

        myapp.model= new Backbone.DeepModel.extend({
            defaults: {
            },

            urlRoot: '/users',

由于某种原因,上述方法似乎无法正常工作。 我想我缺少了一些东西,但不确定是什么。 我正在使用骨干深度模型插件

这是我在调试器中遇到的错误

未捕获的TypeError:对象[object Object]没有方法'apply'

在函数签名中将DeepModel添加到您的范围中:

define([
'jquery',
'underscore',
'backbone',
'deepModel',
], function($, _, Backbone, **DeepModel**) 

如果使用主干和下划线的AMD兼容版本,则可能会使您的生活更轻松。 默认情况下,它们不支持AMD。

https://github.com/amdjs/backbone

https://github.com/amdjs/underscore

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM