gpt4 book ai didi

extjs - 在绑定(bind) View 中应用条件

转载 作者:行者123 更新时间:2023-12-01 15:00:07 25 4
gpt4 key购买 nike

如何在绑定(bind)中应用条件?

鉴于让
{
xtype : 'label',
bind : {
text : '{//--- set text as per the condition }',
hidden : '{//should be true if 'param' in VM is 1 or 2 else should
be false}'
}
}

在 View 模型中,'param' 是一个数据变量。如果值为

param=1, text 应该是 1,

param=2,文本应该是两个,

param=3,文本应该是三个。

通过直接在 View 中应用条件,这是否可能没有公式?

最佳答案

{
xtype : 'label',
bind :
{
text : '{textVal}'==0?'Test':'TEST1234',
hidden : ('{param}'==1 || '{param}'==2)?true:false
}
}

在关联的 viewModel 中,如果有属性 param在数据配置中,可以将其用于绑定(bind)以及如上所述的条件检查。如果 param值正在动态更改,(即 this.getViewModel().setData('param', 1)) 然后代码仍然可以动态隐藏组件。这同样适用于其他配置 viewModel -> data:{textVal:0,param:1} 。如果数据中有一个对象,例如 data:{ config:{ textVal:0 }, param:1 } ,可以使用 bind:{ text:'{config.textVal}' //along with ur condition check }

关于extjs - 在绑定(bind) View 中应用条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27980734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com