Loading Backbone.Relational using Use! plugin

∥☆過路亽.° 提交于 2019-12-12 00:36:37

问题


Backbone Relational is not an AMD compliant library, so I've gone ahead and found the use plugin to ensure underscore and backbone are both loaded as dependencies. Here is my config file

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"]
    }
  }
 });

I've also gone ahead and augmented the Backbone Relational library

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

  Backbone.Relational = {
        showWarnings: true
  };

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

Finally, I am calling relational within a model

 define([

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

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

I am getting an error of cannot set property Relational of undefined. Meaning Backbone is not available. What am I missing?

Some links that I have been using
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


回答1:


Backbone and underscore are not AMD compatible.

Upgrade warning: versions 1.3.0 and higher remove AMD (RequireJS) support.




回答2:


To use (sic) the use plugin you do not need the AMD versions of underscore/backbone. You do need to wrap them though accordingly, i.e. in your require config have:

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

        underscore: {
            attach: "_"
        },

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


来源:https://stackoverflow.com/questions/10659454/loading-backbone-relational-using-use-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!