0

I have created a model and collection for a json to be fetched as shown here.When i'm instantiating in the service i'm getting error that my model is not a constructor.My model uses collection of models for storing time/value pairs. 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();
Mikey
  • 155
  • 4
  • 9
  • 1
    Does `ServiceMonitoringCollection` reference `ServiceMonitoringModel` by chance? PS: Mutable values in a `defaults` objects are a bad idea, use a function for `defaults` if it contains mutable things. – mu is too short May 04 '16 at 18:04
  • ServiceMonitoringCollection uses another model servicePerfomanceModel to create the array of time value pairs... Will change default – Mikey May 04 '16 at 18:26
  • What is the exact error message? Is there a stack trace? – mu is too short May 04 '16 at 18:53

1 Answers1

1

Your problem is:

 var ServiceMonitoringModel = new ServiceMonitoringModel();

You are assigning a value to your Model definition. Try:

 var serviceMonitoringModel = new ServiceMonitoringModel();

Notice the lowercase s

Erik Ahlswede
  • 2,077
  • 2
  • 25
  • 36