Model is not a constructor-Backbone

江枫思渺然 提交于 2020-01-17 05:02:11

问题


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();

回答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



来源:https://stackoverflow.com/questions/37034608/model-is-not-a-constructor-backbone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!