BindinUtils.bindProperty 方法中的函数/三元运算符
我的 mxml 中有一个这样的标签;
<s:Label id="lblChange" text="{_symbol.change>0 ? '+' + _symbol.change:_symbol.change}" />
这工作得很好,但我需要用 BindingUitls 替换通过大括号的绑定,像这样;
_changeWatcher = BindingUtils.bindProperty(lblChange, "text", _symbol, "change");
同样,工作正常,但没有 if/else 情况。所以我想我可以写一个函数来做到这一点;
private function checkValue(val:Number):String {
if (val > 0)
return "+"+val;
else
return val as String;
}
并将其用作 bindProperty 调用中的属性而不是更改;
.bindProperty(lblChange, "text", _symbol, checkValue(_symbol.change));
然而,bindProperty 似乎在这里只接受字符串。那么有什么方法可以绕过这个“功能”呢?
I've got a label in my mxml like this;
<s:Label id="lblChange" text="{_symbol.change>0 ? '+' + _symbol.change:_symbol.change}" />
This works perfectly fine, but I need to replace the binding via curly brackets with BindingUitls, something like this;
_changeWatcher = BindingUtils.bindProperty(lblChange, "text", _symbol, "change");
Again, works fine, but without the if/else case. So I though I could just write a function to do that;
private function checkValue(val:Number):String {
if (val > 0)
return "+"+val;
else
return val as String;
}
and use it as a property in the bindProperty call instead of change;
.bindProperty(lblChange, "text", _symbol, checkValue(_symbol.change));
However, bindProperty seems to accept nothing but strings here. So what way is there to get around this 'feature'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: