模型不是构造函数-主干 [英] Model is not a constructor-Backbone

查看:73
本文介绍了模型不是构造函数-主干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为要获取的json创建了一个模型和集合,如下所示.当我在服务中实例化时,我收到错误消息说我的模型不是构造函数.我的模型使用模型集合来存储时间/值对. ServiceMonitoringModel.js

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

Service.js

 ...
 var ServiceMonitoringModel=require('common/model/server/ServiceMonitoringModel');
 var ServiceMonitoringModel = new ServiceMonitoringModel();

推荐答案

您的问题是:

 var ServiceMonitoringModel = new ServiceMonitoringModel();

您正在为模型定义分配一个值.试试:

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

 var serviceMonitoringModel = new ServiceMonitoringModel();

注意小写字母 s

这篇关于模型不是构造函数-主干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆