ExtJs Data Store值为空,但填充了Store Raw值

时间:2015-06-03 02:36:58

标签: json extjs

因此,我无法确定为什么我的商店的数据值没有为我的itemselector组件填充,但是填充了原始数据值,看起来我的模型和商店设置正确。我正试图利用json数据的第一个特定部分,这就是为什么我将rootProperty设置为'data [0] .options'。只是尝试使用json数据的'Area'集合填充该itemselector。组件如下,任何帮助将不胜感激。

ItemSelector

xtype: 'itemselector',
                        cls: 'itemSelectorPlainPanel',
                        margin: '10 10 10 10',
                        labelAlign: 'top',
                        height: 200,
                        flex: 1,
                        autoScroll: true,
                        id: 'ertcSelector',
                        buttons: ['add', 'remove'],
                        reference: 'ertcSelector',
                        store: Ext.create('cers.store.ManagerFilterStore'),
                        displayField: 'label',
                        allowBlank: true,
                        msgTarget: 'side',
                        fromTitle: 'Available ERTC Home Area',
                        toTitle: 'Selected ERTC Home Area',
                        listeners: {
                         render: function() {
                             console.log(this);
                             /*console.log('Value is ' + this.fromField.store.data.items.length);*/
                            }
                         }

存储

Ext.define('cers.store.ManagerFilterStore', {
    extend: 'cers.util.Store',
    requires:[
        'cers.model.ManagerFilterItems',
        'cers.util.MsgHelper',
        'Ext.data.proxy.Rest'
    ],
    model: 'cers.model.ManagerFilterItems',
    storeId: 'managerFilterId',
    autoLoad: true,
    proxy: {
        type: 'rest',
        method: 'GET',
        url: '/rest/mgrqueue/init',
        extraParams: {
            authUserId: 'eksioog'
        },
        reader: {
            type: 'json',
            rootProperty: 'data[0].options',
            totalProperty: 'total',
            successProperty: 'success',
            messageProperty: 'message'
        }
    },
    listeners: {
        datachanged: function() {
            /*console.log('rawData below!!!!');
            console.log(this.getProxy());
            console.log('Model Info');
            console.log(this.getProxy().getModel().getFields());
            console.log('getData');
            console.log(this.getData());
            console.log('Fields');
            console.log(this.getProxy().getModel().getFields());
            console.log('Model');
            console.log(this.getProxy().getModel());
            console.log('Store');
            console.log(this);
            console.log('Data');
            console.log(this.getData());*/
            console.log('Reader');
            console.log(this.getProxy().getReader());
        }
    },

    constructor: function(){
        this.callParent(arguments);
        /*this.filter('model', 'Area');*/
    }
});

模型

Ext.define('cers.model.ManagerFilterItems', {
    extend: 'cers.util.Model',

    constructor: function (args) {
        this.callParent(args); // Calls the parent constructor of parent class being extended
    },
    fields: [
        { name: 'label', type: 'string'},
        { name: 'value', type: 'string'},
        { name: 'active', type: 'boolean'},
        { name: 'selected', type: 'boolean'}
    ],
    idProperty: 'label',

    getLabel : function() {
        return this.get('label');
    },

    setLabel : function(value) {
        this.set('label', value);
    },

    getValue : function() {
        return this.get('value');
    },

    setValue : function(value) {
        this.set('value', value);
    },

    getActive : function() {
        return this.get('active');
    },

    setActive : function(value) {
        this.set('active', value);
    },

    getSelected : function() {
        return this.get('selected');
    },

    setSelected : function(value) {
        this.set('selected', value);
    }
});

Json Data

{
  "data" : [ {
    "model" : "Area",
    "functionality" : "ManagerQueueFilter",
    "options" : [ {
      "label" : "HeadQuarters",
      "value" : "12",
      "active" : true,
      "selected" : false
    }, {
      "label" : "Northeast",
      "value" : "2",
      "active" : true,
      "selected" : false
    }, {
      "label" : "Testing Area",
      "value" : "41",
      "active" : true,
      "selected" : false
    } ], }
{
    "model" : "User",
    "functionality" : "ManagerQueueFilter",
    "options" : [
{
      "label" : "Green, Ted",
      "value" : "c0gret6_vzwm",
      "active" : false,
      "selected" : false
    }, {
      "label" : "Eksioglu, Oguz",
      "value" : "eksioog",
      "active" : true,
      "selected" : true
    } ]
  } ],
  "total" : 2,
  "success" : true,
  "message" : "Success"

2 个答案:

答案 0 :(得分:0)

尝试将mode属性添加到itemselector

...
mode: 'local',
...

此外,您尚未将valueField设置为“'字段”。

答案 1 :(得分:0)

哦,我刚刚结束手动设置数据等于正在等待datachanged事件的监听器中的原始数据值,如下所示:

listeners: {
        datachanged: function() {
            for(i = 0; i < this.getData().items.length; i++) {
                this.getData().items[i].data = this.getData().items[i].raw;
                console.log('New Data ' + i);
                console.log(this.getData().items[i].data);
            }
        }
    }

它的盗版但它有效,但仍然不知道为什么这些模型实例没有填充。