我找不到在 Text 组件的 htmlText 属性中绑定(bind)变量的方法 我希望能够做这样的事情:
<mx:Text id="bodyText" styleName="bodyText">
<mx:htmlText >
<![CDATA[<img src='assets.OrangeRect' align='left' hspace='0' vspace='4'/> Bonjour {UserData.name} ]]>
</mx:htmlText>
</mx:Text>
我想绑定(bind)UserData.name
最佳答案
"But i still wonder if it is possible to be handled directly in mxml ? Especially if the binded variable changes i need it to be updated in the text component."
Hichem
您可以将属性绑定(bind)到函数调用,这样每当绑定(bind)值发生变化时,函数调用的结果就用作 htmlText
的值:
<mx:Script>
<![CDATA[
function sayHello(userName:String):String
{
var text:String = "<![CDATA[<img src='assets.OrangeRect' align='left' hspace='0' vspace='4'/> Bonjour " + userName + " ]]>";
return text;
}
]]>
</mx:Script>
<mx:Text id="bodyText" styleName="bodyText" htmlText="{sayHello(UserData.name)}" />
这就像是两者的结合 - 在 MXML 中指定您的绑定(bind),但在脚本部分生成值。
关于apache-flex - 如何在 htmltext CDATA 中进行绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2470360/