Flex - 链接栏数据提供程序的问题
我在显示链接栏时遇到一些问题。
我需要显示的数据位于 XML 文件中。 但是,我无法让链接栏显示 xmllist (我确实读到您无法将 xmllllist 设置为链接栏数据提供程序...)。因此,我正在转换对象数组中的 xmllist。
这是一些代码。
XML 文件:
<data>
<languages>
<language id="en">
<label>ENGLISH</label>
<source></source>
</language>
<language id="fr">
<label>FRANCAIS</label>
<source></source>
</language>
<language id="es">
<label>ESPAÑOL</label>
<source></source>
</language>
<language id="jp">
<label>JAPANESE</label>
<source></source>
</language>
</languages>
</data>
将 xmllist 转换为对象数组的 AS 代码:
private function init():void
{
var list:XMLList = generalData.languages.language;
var arr:ArrayCollection = new ArrayCollection;
var obj:Object;
for(var i:int = 0; i<list.length(); i++)
{
obj = new Object;
obj.id = list[i].@id;
obj.label = list[i].label;
obj.source = list[i].source;
arr.addItemAt(obj, arr.length);
}
GlobalData.instance.languages = arr.toArray();
}
链接栏代码:
<mx:HBox horizontalAlign="right" width="100%">
<mx:LinkBar id="language" dataProvider="{GlobalData.instance.languages}" separatorWidth="3" labelField="{label}"/>
</mx:HBox>
不显示分隔符,也不显示标签。 但数组已填充(我测试过)。
感谢您提供的任何帮助=)
问候, BS_C3
@Decado
这是我使用的链接栏的代码:
<mx:LinkBar id="language"
dataProvider="{GlobalData.instance.languages}"
labelFunction="language_labelFunction"
itemClick="language_itemClick(event)"
styleName="GLBLinkBTN"
separatorColor="#FFFFFF"
separatorWidth="1"
linkButtonStyleName="HPLanguages"
/>
这是 labelfunction 的函数:
private function language_labelFunction(item:Object):String
{
return item.label;
}
希望这有帮助。 问候
I'm having some issues displaying a linkbar.
The data I need to display is in a XML file.
However, I couldn't get the linkbar to display a xmllist (I did indeed read that you cannot set a xmlllist as a linkbar dataprovider... ). So, I'm transforming the xmllist in a array of objects.
Here is some code.
XML file:
<data>
<languages>
<language id="en">
<label>ENGLISH</label>
<source></source>
</language>
<language id="fr">
<label>FRANCAIS</label>
<source></source>
</language>
<language id="es">
<label>ESPAÑOL</label>
<source></source>
</language>
<language id="jp">
<label>JAPANESE</label>
<source></source>
</language>
</languages>
</data>
AS Code that transforms the xmllist in an array of objects:
private function init():void
{
var list:XMLList = generalData.languages.language;
var arr:ArrayCollection = new ArrayCollection;
var obj:Object;
for(var i:int = 0; i<list.length(); i++)
{
obj = new Object;
obj.id = list[i].@id;
obj.label = list[i].label;
obj.source = list[i].source;
arr.addItemAt(obj, arr.length);
}
GlobalData.instance.languages = arr.toArray();
}
Linkbar code:
<mx:HBox horizontalAlign="right" width="100%">
<mx:LinkBar id="language" dataProvider="{GlobalData.instance.languages}" separatorWidth="3" labelField="{label}"/>
</mx:HBox>
The separator is not displaying, and neither do the label.
But the array is populated (I tested it).
Thanks for any help you can provide =)
Regards,
BS_C3
@Decado
Here's the code for the linkbar I used:
<mx:LinkBar id="language"
dataProvider="{GlobalData.instance.languages}"
labelFunction="language_labelFunction"
itemClick="language_itemClick(event)"
styleName="GLBLinkBTN"
separatorColor="#FFFFFF"
separatorWidth="1"
linkButtonStyleName="HPLanguages"
/>
And here's the function for the labelfunction:
private function language_labelFunction(item:Object):String
{
return item.label;
}
Hope this helps.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这正是您正在寻找的。看看你能不能适应它。
This does what you're looking for. See if you can adapt it.
我找到了解决我的问题的方法。
我在链接栏中使用了标签函数(而不是标签属性)。使用标签函数就达到了目的。
但我仍然不太明白为什么标签属性不起作用......
I found a solution to my issue.
I used a labelfunction in the linkbar (instead of label property). Using a label function did the trick.
But I still do not quite understand why the label property wasn't working...