防止选择火花列表中的特定项目

发布于 2024-12-06 07:28:20 字数 310 浏览 1 评论 0原文

我有一个 Spark 列表,其中有一个自定义 itemRenderer 用于渲染列表中的每个项目。 我希望阻止用户选择该列表中的项目(基于某些自定义逻辑)。

我实现这一目标的最佳方法是什么?

以下是我的列表的定义方式:

当然,我有一个项目渲染器定义为类 <代码>com.sample.MyItemRenderer。

I have a Spark List which has a custom itemRenderer for rendering each item in the List.
I wish to prevent an item in that list from being selected (based on some custom logic) by the user.

What is the best way I can achieve this?

Here's how my List is defined:

<s:List id="myList" itemRenderer="com.sample.MyItemRenderer" />

and of course, I have a item renderer defined as the class com.sample.MyItemRenderer.

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

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

发布评论

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

评论(1

旧街凉风 2024-12-13 07:28:20

据我所知,项目的选择是由列表单独处理的,所以我想说你可以从那里进行管理。我会在列表中的对象上有一个名为“可选择”或类似的字段,当列表项发生更改时,检查新项目是否实际上可以选择,如果不是,那么您可以选择它清除选择或重置为之前的选择。您可以通过响应列表组件上的“更改”事件并在 IndexChangeEvent 上调用“preventDefault”来实现此目的,如下所示:

protected function myList_changingHandler(event:IndexChangeEvent):void {
    var newItem:MyObject = myList.dataProvider.getItemAt(event.newIndex) as MyObject;
    if(!newItem.selectable) {
        event.preventDefault();
    }
}

// Jumping ahead ...

<s:List id="myList" changing="myList_changingHandler(event)" // ... continue implementation

MyObject 类的相关部分如下:

public class MyObject {

    private var _selectable:Boolean;

    public function MyObject(){

    }

    public function set selectable(value:Boolean):void {
        _selectable = value;
    }

    public function get selectable():Boolean {
        return _selectable;
    }
}

The selection of items is handled by the list alone as far as I know, so I would say that you can manage it from there. I would have a field on the Objects that are in the list called "selectable" or something like that and when the list item is changing check to see if the new item is actually selectable and if it isn't then you can either have it clear the selection or reset to the previous selection. You can accomplish that by reacting to the "changing" event on the list component and calling "preventDefault" on the IndexChangeEvent as follows:

protected function myList_changingHandler(event:IndexChangeEvent):void {
    var newItem:MyObject = myList.dataProvider.getItemAt(event.newIndex) as MyObject;
    if(!newItem.selectable) {
        event.preventDefault();
    }
}

// Jumping ahead ...

<s:List id="myList" changing="myList_changingHandler(event)" // ... continue implementation

The relevant part of the MyObject class is as follows:

public class MyObject {

    private var _selectable:Boolean;

    public function MyObject(){

    }

    public function set selectable(value:Boolean):void {
        _selectable = value;
    }

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