代码之家  ›  专栏  ›  技术社区  ›  Kerempuhh

如何从控制器获取值以形成

  •  0
  • Kerempuhh  · 技术社区  · 11 年前

    我在ExtJS4中构建了一个主/详细表单,作为学习ExtJS的练习。 我想传下去 id 从主表到 detail 当我创建一篇新文章时。 当 create 按钮被按下 detailGrid 这个 身份证件 传递给 controller 。在 控制器 我可以看到 身份证件 通过 console.log 所以我知道它存在于 控制器 . 我如何将其传递到表单?

    控制器:

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

    我需要得到的表格 parentId 来自 控制器

    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 回复  |  直到 11 年前
        1
  •  1
  •   Rob Schmuecker    11 年前

    您可以将变量放在全局命名空间中,以便可以从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}});