使用Use加载Backbone.Relational!插入

时间:2012-05-18 20:43:13

标签: backbone.js requirejs amd backbone-relational

Backbone Relational不是一个兼容AMD的库,所以我一直在寻找使用插件来确保下划线和主干都作为依赖项加载。这是我的配置文件

require.config({
  baseUrl: '../global/js',
  paths: {
    use: 'libs/utilities/use',
    jquery: 'libs/jquery/jquery-min',
    underscore: 'libs/underscore/underscore-min',
    backbone: 'libs/backbone/backbone-optamd3-min',
    text: 'libs/require/text',
    relational: 'libs/backbone/backbone-relational'
  },
  use:  {
    "relational": {
        deps: ["backbone","underscore"]
    }
  }
 });

我也继续前进并扩充了Backbone Relational库

(function(Backbone, _) {
  "use strict";

  Backbone.Relational = {
        showWarnings: true
  };

})(this.Backbone, this._);

最后,我在模型中调用关系

 define([

    'jquery',
    'underscore',
    'backbone',
    'mediator',
    'relational'

    ], function($, _, Backbone, Mediator){

我收到一个错误,无法设置未定义的属性Relational。意思是Backbone不可用。我错过了什么?

我一直在使用的一些链接 https://github.com/tbranyen/use.js
https://github.com/tbranyen/layoutmanager-example/blob/master/app/index.js
https://raw.github.com/PaulUithol/Backbone-relational/master/backbone-relational.js

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

要使用(原文如此) use插件需要AMD版本的下划线/骨干网。 你需要相应地包装它们,即在你的require配置中包含:

    use: {
        backbone: {
            deps: ["use!underscore", "jquery"],
            attach: "Backbone"
        },

        underscore: {
            attach: "_"
        },

        relational: {
            deps: ["use!underscore", "use!backbone"]
        }
        ....
    }