我是骨干新手并尝试简单的抓取:
var segments = Backbone.Model.extend({
url: function() {
return '/campaign-mus/' +
programmeCode + '/get-campaign-mu-json/get-segment-configuration-for-' +
type + '/' + muId;
}
});
segments.fetch().done(function(segmentsJson) {
console.log(segmentsJson);
});
给了我:
Uncaught TypeError: Object function (){ parent.apply(this, arguments); } has no method 'fetch'
知道为什么吗?
谢谢
答案 0 :(得分:5)
'segments'是“类名”(模型定义),而不是实际的实例。你必须像这样实例化模型:
var seg = new segments();
顺便说一句,我建议使用大写的单数词作为“类”(模型)名称。例如
var Segment = Backbone.Model.extend({});
然后
var segment = new Segment();