【问题标题】:How bind a textfield with combo box values in extjs6?如何在 extjs6 中将文本字段与组合框值绑定?
【发布时间】:2015-08-11 02:24:19
【问题描述】:

我在我的应用程序中使用extjs-6。我有一个combo box。这个组合可以有 3 个值。如果用户选择value1value2,则必须注册两个textfield,但如果他选择value3,则必须注册三个textfield

我知道 extjs-6 有一个 reference 配置,我可以使用如下:

Ext.create('Ext.panel.Panel', {
    title: 'Sign Up',

    viewModel: {
        type: 'test'
    },

    items: [{
        xtype: 'checkbox',
        boxLabel: 'Is Admin',
        reference: 'isAdmin'
    },{
        xtype: 'textfield',
        fieldLabel: 'Admin Key',
        bind: {
            disabled: '{!isAdmin.checked}'
        }
    }]
});

我该如何实现这个
注意:这些textfields(value1, vlaue1 的两个主题和value3 的三个主题是必填)。

【问题讨论】:

  • 您是否尝试在复选框上绑定值?绑定:{值:'{checkBoxValue}'}。然后你可以进入 viewModel
  • 如何获得checkBoxValue
  • 你会在 viewModel 上找到它。您也可以根据viewModel中的公式绑定文本字段的隐藏值

标签: javascript extjs reference viewmodel extjs6


【解决方案1】:

在我的示例中,我将根据组合框的选定记录禁用文本字段。有两种(甚至更多)方法可以做到这一点。

  1. 可以绑定combo的选中记录,设置为'disabled' 使用此绑定的文本字段(或任何可绑定配置) 记录。

  2. 您可以使用公式并根据所选值 组合你返回真或假(或选定的另一个属性 记录)设置文本字段的“禁用”。

在视图的声明中绑定选中的记录(不使用viewmodel)

要将所选记录绑定到属性,请将其添加到您的组合配置中:

{
    xtype: 'combo',
    bind: {
        selection: '{selectedRecord}'
    }
}

现在您可以使用该属性来设置禁用。将此添加到文本字段的配置中:

{
    xtype: 'textfield',
    bind: {
        disabled: '{!selectedRecord.value}'
    }
}

您可以在这里找到一个工作示例:https://fiddle.sencha.com/#fiddle/tec

使用公式并返回值(基于所选记录)进行绑定

要获取组合的选定记录,请创建一个公式,该公式使用它的参考配置绑定到组合:

formulas: {
     disableTextField: {
         bind: {
             bindTo: '{data2.selection}',
             deep: true
         },
         get: function(record) {
             return record ? record.id !== 3 : true;
         }
    }
 }

现在将“disableTextField”的返回值绑定到文本字段的所需属性:

{
    xtype: 'combo',
    reference: 'data2'
}, {
    xtype: 'textfield',
    bind: {
        disabled: '{disableTextField}'
    }
}

您可以在这里找到一个工作示例:https://fiddle.sencha.com/#fiddle/te8

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多