2
我正在使用backbone.js以及jquery和underscore.js。
錯誤說:
類型錯誤:CollectorCollection是不是構造
變種收藏家=新CollectorCollection();RequireJs骨幹錯誤集合在創建新集合時不是構造函數
這是我的index.html
<html><heade></head><body><script data-main="js/mainCollector" src="js/libs/require.js"></script></body>
mainCollector.js
require.config({
paths: {
html5shiv: "libs/html5shiv",
jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
jqueryui: "http://code.jquery.com/ui/1.10.3/jquery-ui",
tablesorter: "libs/jquery.tablesorter.min",
script: "script",
underscore: "libs/underscore.min", /*"http://underscorejs.org/underscore",*/
backbone: "libs/backbone.min", /*"http://backbonejs.org/backbone-min",*/
utils: "utils",
collectorModel: "models/collectorModel",
collectorCollection: "collectorCollection",
collectorRouter: "collectorRouter",
edit: "views/Collector/collector_edit",
index: "views/Collector/collector_index",
neww: "views/Collector/collector_new",
row: "views/Collector/collector_row",
show: "views/Collector/collector_show"
},
shim: {
jqueryui: {
deps: ["jquery"],
exports: "Jqueryui"
},
tablesorter: {
deps: ["jquery"],
exports: "TableSorter"
},
script: {
deps: ["jquery"],
exports: "Script"
},
underscore: {
exports: "_"
},
backbone: {
deps: ["underscore", "jquery"],
exports: "Backbone"
}
}
});
require(["backbone", "underscore", "collectorCollection", "collectorRouter"],
function (Backbone, _, CollectorCollection, CollectorRouter) {
var Collectors = new CollectorCollection();
var router = new CollectorRouter({collectors: collectors});
console.log("Start App");
Backbone.history.start();
});
colectorCollection.js
define("collection", [
"underscore",
"backbone",
"collectorModel"
], function(_, Backbone, CollectorModel) {
console.log("Collection loaded");
var CollectorCollection = Backbone.Collection.extend({
// Reference to this collection's model.
url: "api/index.php/Collectors",
model: CollectorModel
});
return CollectorCollection;
});
collectorModel.js
define("model", ["underscore", "backbone"], function(_, Backbone){
console.log("model loaded");
var CollectorModel = Backbone.Model.extend({
urlRoot: 'api/index.php/collectors',
// the root
paramRoot: "collector",
// the default fields
defaults: {
id: null,
name: ""
}
});
return CollectorModel;
});
謝謝。
謝謝,我已經糾正的大寫的失敗,而不是原因。 – mstafkmx
我只注意到你爲你的模塊定義了名字(你的第一個參數),這可能也是問題的一部分。我修改了集合的代碼作爲示例 – nikoshr
@MustaphaKoumach在模塊定義中刪除名稱有幫助嗎? – nikoshr