简体   繁体   English

在Sencha Touch中获取有关“初始化”的容器记录

[英]Get container's record on “initialize” in Sencha Touch

I have a listContainer and on tap of any item in the list, I open another page known as editContainer with the record from list. 我有一个listContainer,点击列表中的任何项目,就会打开另一个名为editContainer的页面,其中包含列表中的记录。 In the edit page, I want to disable a dropdown based on the value of another field, is there any way I can get the values in record in the initialize function of editContainer? 在编辑页面中,我想基于另一个字段的值禁用下拉列表,有什么方法可以在editContainer的initialize函数中获取记录中的值? Here is my code:- 这是我的代码:

onListItemTap:function(dataview,index,target,record,e,eOpts)
{
if(record)
this.editContainer = Ext.create('myApp.view.EditContainer',{title:'Edit Data'});
this.editContainer.setRecord(record);
this.getMainNav().push(this.editContainer);
}

Above code opens editContainer when a list item is selected. 当选择一个列表项时,以上代码将打开editContainer。 Below is my EditContainer 以下是我的EditContainer

Ext.define('myApp.view.EditContainer', {
    extend: 'Ext.Container',

    requires: [
    'Ext.form.Panel',
    'Ext.form.FieldSet',
    'Ext.field.Select'
],

config: {
    id: 'editContainer',
    autoDestroy: false,
    layout: 'fit',
    items: [
        {
            xtype: 'formpanel',
            id: 'editFormPanel',
            padding: 10,
            styleHtmlContent: true,
            autoDestroy: false,
            layout: 'fit',
            items: [
                {
                    xtype: 'fieldset',
                    id: 'nameFieldSet',
                    autoDestroy: false,
                    items: [
                        {
                            xtype: 'textfield',
                            id: 'siteName',
                            itemId: 'mytextfield',
                            label: 'Name',
                            labelWidth: '35%',
                            name: 'name'
                        },
                        {
                            xtype: 'selectfield',
                            id: 'role',
                            itemId: 'myselectfield4',
                            label: 'Role',
                            labelWidth: '35%',
                            name: 'role',
                            options: [
                                {
                                    text: 'Unassigned',
                                    value: 'Unassigned'
                                },
                                {
                                    text: 'Role1',
                                    value: 'role1'
                                }
                            ]
                        },
                        {
                            xtype: 'selectfield',
                            id: 'type',
                            label: 'Type',
                            labelWidth: '35%',
                            name: 'type',
                            options: [
                                {
                                    text: 'Default',
                                    value: 'Default'
                                },
                                {
                                    text: 'Custom',
                                    value: 'custom'
                                }
                            ]
                        },
                        {
                            xtype: 'selectfield',
                            id: 'roleValue',
                            label: 'Role Value',
                            labelWidth: '35%',
                            name: 'rolevalue',
                            options: [
                                {
                                    text: 'value1',
                                    value: 'value1'
                                },
                                {
                                    text: 'value2',
                                    value: 'value2'
                                },
                                {
                                    text: 'value3',
                                    value: 'value3'
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    listeners: [
        {
            fn: 'onTextfieldKeyup',
            event: 'keyup',
            delegate: 'textfield'
        },
        {
            fn: 'onSelectfieldChange',
            event: 'change',
            delegate: 'selectfield'
        }
    ]
},

onTextfieldKeyup: function(textfield, e, eOpts) {
    this.fireEvent('change', this);
},

onSelectfieldChange: function(selectfield, newValue, oldValue, eOpts) {
    this.fireEvent('change', this);
},

initialize: function() {
    this.callParent();
    var record;

    //Code to disable roleValue selectfield if Role is unassigned.
},

updateRecord: function(newRecord) {
    var me = this,
        myPanel = me.down('#editFormPanel');

    if(myPanel)
        myPanel.setRecord(newRecord);

},

saveRecord: function() {
    var me =this,
        myStore = Ext.data.StoreManager.lookup('MyStore');

    var formPanel = me.down('#editFormPanel'),
        record = formPanel.getRecord();
    formPanel.updateRecord(record);

    return record;
}

});

Since creating your editContainer and setting its data are two different steps in your code you can't use the initialize method of the editContainer. 由于在代码中创建了editContainer并设置了其数据是两个不同的步骤,因此不能使用editContainer的initialize方法。

But you can override the setRecord method of the editContainer, so it additionally disables the dropdown. 但是您可以覆盖editContainer的setRecord方法,因此它另外会禁用下拉菜单。

Since you push the editContainer onto a navigation view you could also use the activate event of the editContainer to disable the dropdown. 由于将editContainer推到导航视图上,因此您还可以使用editContainer的activate事件禁用下拉菜单。

Maybe you can create a quick store on the fly, as a place to have a reference to that data... 也许您可以即时创建一个快速存储,作为参考该数据的地方...

    //in your controller where you set the record

    var mod = Ext.define('app.model.PanelDataModel', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                'roleValue'
            ]
        }
    });

    var sto = Ext.create('Ext.data.Store', {
        model: mod,
        id:'PanelDataStore'
    });

    sto.add({
        roleValue: record.roleValue
    });
    sto.sync();


    //Now in your panel's initialize method:

    var pstore = Ext.getStore('PanelDataStore');
    pstore.load();

    if(pstore.data.all[0].data.roleValue == 'unassigned'){
        Ext.getCmp('roleValue').setDisabled(true);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM