`
darrenzhu
  • 浏览: 785649 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Flex中无法选中DataGrid组件的行

阅读更多
Cannot select certain rows in List component or DataGrid component

The problem is that for each item in data provider, we must get a unique ID (UID) for it, if two or more items in data provider get the same UID after call itemToUID method, then we only can select one of them and can never successful to select the rest of them. To avoid this problem, refer to the following itemToUID method to understand how Flex components generate the UID and avoid generating the same UID.
Please Note, the following method itemToUID are quoted from class ListBase of SDK source code. 
We can use: copyOfOldObject= ObjectUtil.copy(oldObject) to get a new instance, then when we add  the copy to the ArrayCollection which is the binding source of dataProvider, we will get different UID for each instance, then we won’t have the problem.
    /**
     *  Determines the UID for a data provider item.  All items
     *  in a data provider must either have a unique ID (UID)
     *  or one will be generated and associated with it.  This
     *  means that you cannot have an object or scalar value
     *  appear twice in a data provider. For example, the following
     *  data provider is not supported because the value "foo"
     *  appears twice and the UID for a string is the string itself:
     *
     *  <blockquote>
     *  <code>var sampleDP:Array = ["foo", "bar", "foo"]</code>
     *  </blockquote>
     *
     *  Simple dynamic objects can appear twice if they are two
     *  separate instances. The following is supported because
     *  each of the instances will be given a different UID because
     *  they are different objects:
     *
     *  <blockquote>
     *  <code>var sampleDP:Array = [{label: "foo"}, {label: "foo"}]</code>
     *  </blockquote>
     *
     *  Note that the following is not supported because the same instance
     *  appears twice.
     *
     *  <blockquote>
     *  <code>var foo:Object = {label: "foo"};
     *  sampleDP:Array = [foo, foo];</code>
     *  </blockquote>
     *
     *  @param data The data provider item.
     *
     *  @return The UID as a string.
     */
    protected function itemToUID(data:Object):String
    {
        if (data == null)
            return "null";
        return UIDUtil.getUID(data);
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics