防止选择火花列表中的特定项目 [英] Prevent selection of a particular item in spark list

查看:77
本文介绍了防止选择火花列表中的特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spark列表,该列表具有一个自定义itemRenderer,用于呈现列表中的每个项目. 我希望防止用户(基于某些自定义逻辑)选择该列表中的项目.

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" />

当然,我有一个定义为类com.sample.MyItemRenderer的项目渲染器.

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

推荐答案

据我所知,列表的选择仅由列表处理,因此我可以说您可以从那里进行管理.我会在列表中的对象上有一个名为"selectable"或类似名称的字段,当列表项发生更改时,请检查新项是否实际上是可选择的,如果不是,则可以将其选中清除选择或重置为上一个选择.您可以通过对列表组件上的"changing"事件做出反应并在IndexChangeEvent上调用"preventDefault"来完成此操作,如下所示:

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

MyObject类的相关部分如下:

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;
    }
}

这篇关于防止选择火花列表中的特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆