【问题标题】:Is there a way to directly use Enums with the tagfield in extjs?有没有办法在 extjs 中直接使用 Enums 和 tagfield?
【发布时间】:2019-12-02 14:55:49
【问题描述】:

我必须创建多选组合框。我有一个普通的组合框,它使用枚举加载其数据。这工作正常。但是我必须允许在这个组合框中进行多选,为此我已将 xtype 从组合框更改为标记字段。但是列表没有填充,因为标签字段需要存储,在我的情况下,我从 Enum 类中获取值,该类返回以下格式的值:

[{label: "label1",value: "value1"},
{label: "label2",value: "value2"}]

如何将标签字段与枚举一起使用?

我的代码是这样的:

tbar : {
    items : [ {
       xtype : 'container',
       layout : 'hbox',
       items : [ {
          xtype : 'combobox',
          labelWidth : 150
       }]
}

【问题讨论】:

  • 你能创建一个小提琴吗?为什么你不想使用商店?
  • 我可以使用store,但问题是我是现有的代码库我从枚举中获取数据
  • 有没有什么办法可以在 store 中使用 enum 数据并在 tagfield 中使用?

标签: extjs


【解决方案1】:

对不起,如果我没有正确理解您的问题,但如果您的数据返回像

[{label: "label1",value: "value1"},
{label: "label2",value: "value2"}]

你可以像这样定义你的tagfield

//get ref of your data
let myData = [{
    label: "label1",
    value: "value1"
        }, {
    label: "label2",
    value: "value2"
        }]

还有

items: [{
    xtype: 'container',
    layout: 'hbox',
    items: [{
        xtype: 'tagfield',
        store: {
            storeId: 'MyStoreId',
            data: myData //set the data in the store
        },
        labelWidth: 150,
        displayField: 'label',
        valueField: 'value'
     }]
}]

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 1970-01-01
    • 2018-10-29
    • 2018-11-10
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    相关资源
    最近更新 更多