0
ここに示すようにjsonをフェッチするモデルとコレクションを作成しました。サービスでインスタンス化しているときに、私のモデルがコンストラクタではないというエラーが発生しています。私のモデル時間と値のペアを格納するモデルのコレクションを使用します。 ServiceMonitoringModel.jsモデルはコンストラクタ - バックボーンではありません
define(function(require) {
'use strict';
var _ = require('underscore');
var Backbone = require('backbone');
var ServiceMonitoringCollection=require('./ServiceMonitoringCollection');
var ServiceMonitoringModel = Backbone.Model.extend({
modelNAme: 'ServiceMonitoringModel',
idAttribute: 'id',
defaults: {
// todo
content_type: '',
content_graph: {
capacity: null,
performance: {
memory: new ServiceMonitoringCollection(),
cpu: new ServiceMonitoringCollection()
}
}
},
initialize: function() {
//todo
},
validate: function(attributes) {
},
parse: function(response) {
return {
content_type: response.content_type,
content_graph: {
capacity:this.getDeepJsonValue(response, 'capacity'),
performance: {
memory: new ServiceMonitoringCollection(this.getDeepJsonValue(response, 'memory'),{parse:true}),
cpu: new ServiceMonitoringCollection(this.getDeepJsonValue(response, 'cpu'),{parse:true})
}
}
};
}
});
return ServiceMonitoringModel;
});
Service.js
...
var ServiceMonitoringModel=require('common/model/server/ServiceMonitoringModel');
var ServiceMonitoringModel = new ServiceMonitoringModel();
は偶然 'ServiceMonitoringCollection'リファレンス' ServiceMonitoringModel'ていますか? PS: 'defaults'オブジェクトの可変値は悪い考えです。変更可能なものがあれば、' defaults'に関数を使用してください。 –
ServiceMonitoringCollectionは、別のモデルservicePerfomanceModelを使用して時間値のペアの配列を作成します。デフォルトを変更します – Mikey
正確なエラーメッセージは何ですか?スタックトレースはありますか? –