1

我尝试建立一个激活 useComponents 的列表。到目前为止,它工作正常。我将用切换字段表示的数据记录“内部状态”不包含“0”或“1”作为值,而是“开”或“关”。所以我尝试扩展应用方法并检查当前值

this.getRecord().get('internal_state')

但在所有情况下,结果都是空的。有人有办法吗?这样,在许多情况下,我将不得不在显示之前对核心数据进行维护。

我的设备列表如下所示:

Ext.define('HomeBox.view.DeviceListView', {
extend: 'Ext.dataview.List',
xtype: 'devicelist',
requires: [
    'Ext.plugin.PullRefresh',
    'HomeBox.view.DeviceListItemView'
],
config: {
    useComponents: true,
    defaultType: 'devicelistitem',
    useHeaders: false,
    plugins: [
        { xclass: 'Ext.plugin.PullRefresh' }
    ]
}

});

和项目视图:

Ext.define('HomeBox.view.DeviceListItemView', {
extend: 'Ext.dataview.component.DataItem',
requires: [
    'Ext.field.Toggle'
],
xtype: 'devicelistitem',
config: {
    layout: 'hbox',
    styleHtmlContent: true,
    DeviceName: {
        flex: 1,
        tpl: '{.}',
        data: ''
    },
    DeviceToggle: {
        flex: 2
    },
    dataMap: {
        getDeviceName: {
            setData: 'Name'
        },
        getDeviceToggle: {
            setValue: 'internal_state'
        },
    }
},
applyDeviceName: function(config) {
    return Ext.factory(config, Ext.Component, this.getDeviceName());
},
updateDeviceName: function(newName, oldName) {
    if (newName) {
        this.add(newName);
    }

    if (oldName) {
        this.remove(oldName);
    }
},
applyDeviceToggle: function(config) {
    return Ext.factory(config, Ext.field.Toggle, this.getDeviceToggle());
},
updateDeviceToggle: function(newOne, oldOne) {
    if (newOne) {
        this.add(newOne);
    }

    if (oldOne) {
        this.remove(oldOne);
    }
},

});

4

1 回答 1

0

从 Ext.field.Toggle 扩展自定义切换字段并添加

setValue: function(newValue) {
    if (newValue === 'on') {
        newValue = 1;
    }

    var oldValue = this.getValue();
    if (oldValue != newValue) {
        this.getComponent().setValue(newValue);

        this.fireEvent('change', this, newValue, oldValue);
    }

    return this;
},

getValue: function() {
    return (this.getComponent().getValue() == 'on') ? 1 : 0;
},
于 2014-09-19T13:55:08.907 回答