Sencha Touch 2: Компонент DataItem, getRecord() в элементах списка

Я пытаюсь создать список с активированными useComponents. Пока все отлично работает. Корд данных "internal_state", который я буду представлять с полем переключения, не содержит "0" или "1" в качестве значения, но "включен" или "выключен". Поэтому я попытался расширить метод apply и проверить текущее значение с помощью

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

});

1 ответ

Расширить пользовательское поле переключения из 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;
},
Другие вопросы по тегам