Flex - 链接栏数据提供程序的问题

发布于 2024-08-25 12:42:21 字数 2020 浏览 2 评论 0原文

我在显示链接栏时遇到一些问题。

我需要显示的数据位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衬遮猫 2024-09-01 12:42:21

这正是您正在寻找的。看看你能不能适应它。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Array id="dataProvider">
        <mx:Object id="en" label="English" />
        <mx:Object id="fr" label="French" />
        <mx:Object id="es" label="Espanol" />
        <mx:Object id="jp" label="Japanese" />
    </mx:Array> 

    <mx:LinkBar
        horizontalCenter="0"
        verticalCenter="0"
        dataProvider="{dataProvider}"
        labelField="label" />
</mx:Application>

This does what you're looking for. See if you can adapt it.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Array id="dataProvider">
        <mx:Object id="en" label="English" />
        <mx:Object id="fr" label="French" />
        <mx:Object id="es" label="Espanol" />
        <mx:Object id="jp" label="Japanese" />
    </mx:Array> 

    <mx:LinkBar
        horizontalCenter="0"
        verticalCenter="0"
        dataProvider="{dataProvider}"
        labelField="label" />
</mx:Application>
变身佩奇 2024-09-01 12:42:21

我找到了解决我的问题的方法。
我在链接栏中使用了标签函数(而不是标签属性)。使用标签函数就达到了目的。

但我仍然不太明白为什么标签属性不起作用......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文