Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取容器';"的纪录;初始化";触碰森查_Javascript_Extjs_Sencha Touch 2_Sencha Architect - Fatal编程技术网

Javascript 获取容器';"的纪录;初始化";触碰森查

Javascript 获取容器';"的纪录;初始化";触碰森查,javascript,extjs,sencha-touch-2,sencha-architect,Javascript,Extjs,Sencha Touch 2,Sencha Architect,我有一个listContainer,只要点击列表中的任何项目,我就会打开另一个名为editContainer的页面,其中包含列表中的记录。在编辑页面中,我想禁用基于另一个字段的值的下拉列表,是否有任何方法可以在editContainer的初始化函数中获取记录中的值?这是我的密码:- onListItemTap:function(dataview,index,target,record,e,eOpts) { if(record) this.editContainer = Ext.create('m

我有一个listContainer,只要点击列表中的任何项目,我就会打开另一个名为editContainer的页面,其中包含列表中的记录。在编辑页面中,我想禁用基于另一个字段的值的下拉列表,是否有任何方法可以在editContainer的初始化函数中获取记录中的值?这是我的密码:-

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);
}
上面的代码在选择列表项时打开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;
}

});

也许您可以动态创建一个快速存储,作为对该数据的引用

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

由于在代码中创建editContainer和设置其数据是两个不同的步骤,因此不能使用editContainer的initialize方法

但是您可以覆盖editContainer的
setRecord
方法,因此它还禁用了下拉列表


由于将editContainer推到导航视图上,您还可以使用editContainer的
激活
事件来禁用下拉列表。

谢谢@Martin,如果我覆盖setRecord,则我的保存功能会出现错误。是否有任何关于setRecord实施的文件?在setRecord中,我正在设置所有字段的值,并且有一个roleValue的条件(它正在工作),但由于某种原因,这中断了我的数据保存。我不得不在容器的setRecord中调用formPanel.setRecord(record),它工作得很好。谢谢@Martin