快速提问...我有一个如此定义的requirejs设置......它的工作时间约占8-10%。似乎资源有时没有及时加载。我可以以确保其下方代码正确运行的方式包装上面的var require列表吗?我无法解决的错误是:
未捕获错误:尚未为上下文加载模块名称“views / association / Associations”:_
define(function( require ){
// requirejs - too many includes to pass in the array
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
namespace = require('namespace'),
// models
CustomerModel = require('models/customer/customer'),
// collections
// views
BaseView = require('views/baseView'),
Auth = require('views/auth/Auth'),
SideNav = require('views/sidenav/SideNav'),
CustomersView = require('views/customer/Customers'),
AssociationsView = require('views/association/Associations'),
//CustomerListCpeView = require('views/customer/CustomerListCpe'),
//CustomerAddCpeView = require('views/customer/CustomerAddCpe'),
// templates
CustomerDetailTemplate = require('text!templates/customer/customerDetail.html');
答案 0 :(得分:7)
即使使用“传统”或非糖方法(http://requirejs.org/docs/whyamd.html#sugar),此错误仍然存在。事实证明,在重构期间,我意外地将一个循环导入引入了代码库。删除该循环导入会删除此错误。
答案 1 :(得分:3)
将其更改为
define([
'jquery',
'underscore',
'backbone',
// ...
'views/association/Associations'
// ...
], function($, _, Backbone, /* ..., */ AssociationsView) {
// ...
});