如何从控制器到表单获取值

时间:2015-03-18 12:17:37

标签: extjs extjs4.2

我在ExtJS4中构建了一个主/详细信息表单,作为学习ExtJS的练习。 我想在创建新文章时将id从主表格传递到detail表单。 在create中按下detailGrid按钮后,id会传递给controller。在controller中,我可以通过id查看console.log的输出,因此我知道它存在于controller中。 如何将其传递给表单?

控制器:

{    
    var detailgrid = button.up('userdetail');      
    var parentId = detailgrid.getParentId();
    console.log(parentId);
    var view = Ext.widget('detailadd');  
},

我需要从parentId

获取controller的表单
Ext.define('calsberg.view.user.DetailsAdd', {
    extend: 'Ext.window.Window',
    alias: 'widget.detailadd',
    title: 'Add Artikli',
    config:
    {
        parentId: parentId
    },
    layout: 'fit',
    autoShow: true,
    initComponent: function () {
        this.items = [
            {
                xtype: 'form',
                bodyStyle: {
                    background: 'none',
                    padding: '10px',
                    border: '0'
                },
                items: [
                    {
                        xtype: 'textfield',
                        name: 'parentId',
                        value: this.getParentId()
                    },
                    {                        
                        xtype: 'textfield',
                        name: 'sifra',
                        allowBlank: false,
                        fieldLabel: 'Šifra'
                    },
                    {
                        xtype: 'textfield',
                        name: 'naziv',
                        allowBlank: false,
                        vtype: 'naziv',
                        fieldLabel: 'Naziv'
                    },

1 个答案:

答案 0 :(得分:1)

您可以将变量放在全局命名空间中,以便可以从App中的任何位置引用它,例如。

// MyApp would already be initialised in app.js
MyApp.parentId = detailgrid.getParentId();

// then you could reference it anywhere else thereafter
Ext.define('calsberg.view.user.DetailsAdd', {
    extend: 'Ext.window.Window',
    alias: 'widget.detailadd',
    title: 'Add Artikli',
    config:
    {
        parentId: MyApp.parentId
    }
.....

或者您可以在创建小部件时传入配置对象,例如

var detailgrid = button.up('userdetail');      
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd', {config:{parentId:parentId}}); 
相关问题