我有一个非 AMD javascript,其中包含我的自定义函数,例如:
function getItemIndexById(items, id){
for(var i = 0; i < items.length; i++){
if(items[i].ID == id) return i;
}
return false;
}
//more than one define custom function here.
这里 main.js 文件:
requirejs.config({
enforceDefine: true,
paths: {
"jquery": "libs/jquery/jquery-min",
"underscore": "libs/underscore/underscore-min",
"backbone": "libs/backbone/backbone-min",
"custom" : "libs/scripts/customejs"
},
shim: {
"underscore": {
deps: [],
exports: "_"
},
"backbone": {
deps: ["jquery", "underscore"],
exports: "Backbone"
}
}
});
然后我在我的视图中定义:
define(["jquery" ,
"underscore" ,
"backbone" ,
"custom"
],function($ , _ , Backbone, Custom){
//.....
}
我在Uncaught Error: No define call for custom
.
我必须将我的自定义 js 转换为 AMD 吗?谁能解释一下这个问题。谢谢。