これが機能しない理由がわからない場合、アプリは正常に読み込まれます。json ファイルを要求しなくても load 関数が呼び出されるたびにエラーが発生します。
この同じコードを使用してJavaコントローラーからデータをロードしましたが、静的jsonファイルがどのように異なるかはわかりません。
景色:
define([
'jquery',
'underscore',
'backbone',
'validate',
'collections/getBusiness',
'text!templates/home/homeTemplate.html'
], function($, _, Backbone, validate, getBusiness, homeTemplate){
var HomeView = Backbone.View.extend({
el: $("#page"),
events: {
'click #data': 'data'
},
data: function(e) {
getBusiness.fetch({
success: function(r) {
},
error: function(r) {
alert('error!');
}
});
},
render: function(){
this.$el.html(homeTemplate);
}
});
return HomeView;
});
モデル:
define([
'underscore',
'backbone'
], function(_, Backbone) {
var getModel = Backbone.Model.extend({
});
return getModel;
});
コレクション:
define([
'jquery',
'underscore',
'backbone',
'models/getModel'
], function($, _, Backbone, getModel){
var getBusiness = Backbone.Collection.extend({
model: getModel,
url: '../../json/data.json',
sync: function(method, model, options) {
options.timeout = 100000;
options.contentType = "application/json";
options.cache = false;
options.dataType = "json";
return Backbone.sync(method, model, options);
},
parse: function(response) {
return this.result;
},
});
return new getBusiness;
});