Flex/AS3 多状态项目渲染器问题

发布于 2024-08-08 02:47:24 字数 336 浏览 1 评论 0原文

我创建了一个具有 3 种状态的模块作为 itemrenderer。这些状态称为电影、歌曲和电视节目。基本状态为空。 itemRenderer 由 Hbox、Vbox 和标签组成。

我创建了一个列表组件。

我想要做的是填充列表组件中的数据并使用我的 ItemRenderer 使其可见。根据从数据库中提取的数据,我想显示 itemRenderer 的正确状态。因此,如果从数据库中提取的记录是一首歌曲,我想显示歌曲状态,如果是一部电影,我想显示电影状态等等。

因此,根据提取的数据,我想更改 itemrenderer 的当前状态。我该怎么做? 有人可以给我举个例子,我将如何编写这段代码吗?

谢谢

I have created a module with 3 states as an itemrenderer. The states are called Movies, Songs and TvShows. The base state is empty. The itemRenderer consists of Hbox, Vboxes and labels.

And I have created a List component.

What I want to do is to populate data in my List component and make it visible using my ItemRenderer. Depending on the data that is pulled out from the database I want to show the itemRenderer's correct state. Hence if the record pulled out from the database is a song, I want to display the Song state, if it is a movie, I want to show the Movie state and so on.

So depending on the data that's pulled out, I would like to change the current state of itemrenderer. How would i do that?
Can anybody show me an example how i would make this code?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

春庭雪 2024-08-15 02:47:24

重写 CustomItemRenderer 的 set data 方法并根据数据分配适当的状态。

override public function set data(value:Object):void
{
  super.data = value;
  if(data.type == "song")
    this.currentState = SONG_STATE;
  else if(data.type == "movie")
    this.currentState = MOVIE_STATE;
  else if //and so on...
}

override the set data method of your CustomItemRenderer and assign the appropriate state based on the data.

override public function set data(value:Object):void
{
  super.data = value;
  if(data.type == "song")
    this.currentState = SONG_STATE;
  else if(data.type == "movie")
    this.currentState = MOVIE_STATE;
  else if //and so on...
}
離人涙 2024-08-15 02:47:24

谢谢,效果很好。
我唯一注意到的是:

this.currentState = MOVIE_STATE;

应该

this.currentState = "MOVIE_STATE";

感谢

DJ

thanks it worked well.
The Only thing i notice was that:

this.currentState = MOVIE_STATE;

should be

this.currentState = "MOVIE_STATE";

thanks

DJ

叫嚣ゝ 2024-08-15 02:47:24

使用上述选项,您需要通过循环数据数组集合并将类型设置为另一个状态名称来调整所有数据。

也许更好的解决方案是循环遍历列表中的所有项目并更改状态;

private function changeItemrendererState():void
    {
        var item:mycustomitemrenderer;

        for(var i:uint = 0; i < itemlist.numElements; i++)
        {
            item = itemlist.getElementAt(i) as mycustomitemrenderer;

            item.currentState = "mynewstate";
        }
    }
<s:Scroller focusEnabled="false" hasFocusableChildren="true">   
        <s:DataGroup dataProvider="{mydata}"  itemRenderer="skins.mycustomitemrenderer"  width="100%" height="100%" id="itemlist">
            <s:layout>
                <s:TileLayout horizontalGap="2" verticalGap="2" columnAlign="justifyUsingWidth"/>
            </s:layout>
        </s:DataGroup>
</s:Scroller>

如果您使用 useVirtualLayout="true" 这将不起作用,它只会影响可见项目。

with the above option you need to adjust all your data by looping trough your data arraycollection and setting the type to another state name.

Perhaps a better solution is looping trough all items of the list and change the state;

private function changeItemrendererState():void
    {
        var item:mycustomitemrenderer;

        for(var i:uint = 0; i < itemlist.numElements; i++)
        {
            item = itemlist.getElementAt(i) as mycustomitemrenderer;

            item.currentState = "mynewstate";
        }
    }
<s:Scroller focusEnabled="false" hasFocusableChildren="true">   
        <s:DataGroup dataProvider="{mydata}"  itemRenderer="skins.mycustomitemrenderer"  width="100%" height="100%" id="itemlist">
            <s:layout>
                <s:TileLayout horizontalGap="2" verticalGap="2" columnAlign="justifyUsingWidth"/>
            </s:layout>
        </s:DataGroup>
</s:Scroller>

This will not work if you use useVirtualLayout="true" it then would only affect the visible items.

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