Sencha Touch 2:组件DataItem,listitems中的getRecord()

时间:2014-09-06 21:05:24

标签: listview extjs sencha-touch dataitem

我尝试使用激活的useComponents构建一个列表。到目前为止它工作正常。 datarecord' internal_state'我用togglefield表示的不包含" 0"或" 1"作为价值,但是" on"或"关闭"。 所以我尝试扩展apply方法并使用

检查当前值
this.getRecord().get('internal_state')

但在所有情况下,结果都是null。任何有方法的人? 通过这种方式,我必须在显示之前对核心数据进行维护。在许多情况下。

我的设备列表如下:

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);
    }
},

});

1 个答案:

答案 0 :(得分: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;
},