我正在使用backbone.js 以及jquery 和underscore.js。
错误说:
TypeError: CollectorCollection is not a constructor
var collectors = new CollectorCollection();
这是我的 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();
});
收集器集合.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;
});
收集器模型.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;
});
谢谢。