2016-05-04 14 views
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(); 
+1

は偶然 'ServiceMonitoringCollection'リファレンス' ServiceMonitoringModel'ていますか? PS: 'defaults'オブジェクトの可変値は悪い考えです。変更可能なものがあれば、' defaults'に関数を使用してください。 –

+0

ServiceMonitoringCollectionは、別のモデルservicePerfomanceModelを使用して時間値のペアの配列を作成します。デフォルトを変更します – Mikey

+0

正確なエラーメッセージは何ですか?スタックトレースはありますか? –

答えて

0

あなたの問題は、次のとおりです。

var ServiceMonitoringModel = new ServiceMonitoringModel(); 

あなたのモデル定義に値を代入しています。試してみてください:

var serviceMonitoringModel = new ServiceMonitoringModel(); 

お知らせ小文字

+0

ありがとうErik it worked .... !!! – Mikey

関連する問題