如何将本地json数据加载到Extjs数据模型

时间:2015-04-08 05:53:55

标签: javascript json extjs

我的ExtJS模型定义如下:

Ext.define("WinEvents", {
    extend: 'Ext.data.Model',
    fields: ['eventName', 'domainId','eventId', 'proteanService', sviceId'],                            
    hasMany: { model: 'WinServices', name: 'services'},                         
    proxy: {
        type: 'ajax',  
        method:'GET',
        url : '../js/modules/tree_with_json/tree_model.json',  
        reader: {
            type: 'json',
            root: 'events'
        }
    }
});

这里,tree_model.json是带有suffix.json的空白文件 我命名为' selectedEventsServices'它的值是如下所示的json数据。



{
  "domainID" : "CONSUMERTELEMATICS_0.1",
  "domain" : "consumerTelematics",
  "tenantId": "4"
  "tenantName": "FOURRR"
  "tenantOUId": "13"
  "tenantOuName": "OSRTC Corp"
  "events" : [{
    "eventID" : "POS0.1",
    "event" : "pos0.1",
    "domainID" : "CONSUMERTELEMATICS_0.1",
    "services" : [{
        "proteanService" : "accident",
        "serviceID" : "SER_0.1_1",
        "domainID" : "CONSUMERTELEMATICS_0.1",
        "proteanRelatedService" : null,
        "eventID" : "POS0.1"
     },{
        "proteanService" : "assistanceService",
        "serviceID" : "SER_0.1_2",
        "domainID" : "CONSUMERTELEMATICS_0.1",
        "proteanRelatedService" : null,
        "eventID" : "POS0.1"
    }]
}]
 }




因此,如上所述,值是动态的,json结构化数据将保存到selectedEventsServices变量。 现在问题是如何将selectedEventsServices变量值写入tree_model.json文件?

或者在本地调用Ext.data.Model时是否有任何方法可以从变量中获取值?

1 个答案:

答案 0 :(得分:0)

目前还不太清楚你到底想做什么。但是当然可以从变量创建模型。请查看手册Extjs.data.Model以获取示例:

var user = Ext.create('User', {
    id : 'ABCD12345',
    name : 'Conan',
    age : 24,
    phone: '555-555-5555'
});