要求用木偶创造js

时间:2014-09-05 12:54:37

标签: javascript jquery backbone.js marionette backbone-views

我在控制台中遇到错误。你能帮我解决吗?

我已经包含了requirejs和必要的主干库。

JSBin Demo

我的代码

require.config({
  paths : {
    backbone : '//jashkenas.github.io/backbone/backbone-min.js',
    underscore : '//jashkenas.github.io/underscore/underscore-min.js',
    jquery : '//code.jquery.com/jquery-2.1.1.min.js',
    marionette : 'http://marionettejs.com/downloads/backbone.marionette.min.js'
  },
  shim : {
    jquery : {
      exports : 'jQuery'
    },
    underscore : {
      exports : '_'
    },
    backbone : {
      deps : ['jquery', 'underscore'],
      exports : 'Backbone'
    },
    marionette : {
      deps : ['jquery', 'underscore', 'backbone'],
      exports : 'Marionette'
    }
  }
});

1 个答案:

答案 0 :(得分:2)

首先,您不需要在html中添加backbone,jquery和其他库的脚本标记,因为您已经使用requirejs api包含它们。 其次,建议您将定义代码放在一个文件中,或者您应该为其命名。

更多信息,请参见此处:http://requirejs.org/docs/errors.html#mismatch

  

确保通过RequireJS API加载调用define()的所有脚本。   不要在HTML中手动编写脚本标记以加载其中包含define()调用的脚本。

     

如果手动编写HTML脚本标记代码,请确保它只包含命名模块,并且具有相同的匿名模块   名称作为该文件中的一个模块未加载。