Flex Tree 不选择(“突出显示”)selectedIndices

发布于 2024-12-13 15:13:37 字数 2251 浏览 0 评论 0原文

我有一系列应在树控件中选择的项目。正如您从下面的代码中看到的,我将此数组绑定到树的 selectedIndices 属性。 selectedItems 没有在树中正确选择(选择一些其他项目并且始终选择根)。Flex 似乎“忽略”我的项目(选择一些其他索引)。我错过了什么吗?

也许我以错误的方式处理这个问题?

感谢您的帮助!

我的 XMLList:-

<fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <fx:XMLList id="XMLList">
        <node>
            <node name="max">
                <node name="Emanuele"
                      surname="Tatti" age="23" wage="1200"/>
                <node name="Francesco" 
                      surname="Rapana " age="22" wage="1000"/>
                <node name="Constantin"
                      surname="Moldovanu" age="23" wage="1200"/>
                <node name="Marco" 
                      surname="Casario" age="29" wage="1500">
                    <node name="Marco" 
                          surname="Casario" age="29" wage="1500">
                        <node name="Marco" 
                              surname="Casario" age="29" wage="1500">
                            <node name="Marco" 
                                  surname="Casario" age="29" wage="1500">
                            </node>
                        </node>
                    </node>                 
                </node>
            </node>

        </node>
        </fx:XMLList>
</fx:Declarations>

我的动作脚本功能:-

public function select_tree():Void 
{
tree.validateNow();
var allItems:Array = new Array();
for(var n:Int =2;n<7;n+2)       
{
        allItems[n]=n; // o/p- 2,4,6
}

tree.selectedIndices = allItems1;   //2,4,6 items should select ,but 0,2,4,5 are selected why?
      }

*****My MXML:-*****
<mx:Button id="btn" label="Find Unmatch Nodes" width="221" height="30" click="select_tree()"/>



<mx:Tree id="tree"  right="10" top="54" bottom="10" width="49.5%" dataProvider="{XMLList}"
    fontFamily="Verdana" fontSize="11" showScrollTips="true"
    allowMultipleSelection="true"
    alternatingItemColors="[#F5F5F5]"
    labelField="@label" selectionColor="#ECF335" showRoot="false"/>

I have an array of items that should be selected in my tree control. As you can see from my code below,I bind this array to the selectedIndices property of the tree.
The selectedItems are not properly selecting in tree(selecting some other items and always root is selected).Flex seems to "ignore" my items (selects some other indices). Am I missing something?

Perhaps I'm going about this in wrong way?

Thanks for your help!

My XMLList:-

<fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <fx:XMLList id="XMLList">
        <node>
            <node name="max">
                <node name="Emanuele"
                      surname="Tatti" age="23" wage="1200"/>
                <node name="Francesco" 
                      surname="Rapana " age="22" wage="1000"/>
                <node name="Constantin"
                      surname="Moldovanu" age="23" wage="1200"/>
                <node name="Marco" 
                      surname="Casario" age="29" wage="1500">
                    <node name="Marco" 
                          surname="Casario" age="29" wage="1500">
                        <node name="Marco" 
                              surname="Casario" age="29" wage="1500">
                            <node name="Marco" 
                                  surname="Casario" age="29" wage="1500">
                            </node>
                        </node>
                    </node>                 
                </node>
            </node>

        </node>
        </fx:XMLList>
</fx:Declarations>

My Action Script Function:-

public function select_tree():Void 
{
tree.validateNow();
var allItems:Array = new Array();
for(var n:Int =2;n<7;n+2)       
{
        allItems[n]=n; // o/p- 2,4,6
}

tree.selectedIndices = allItems1;   //2,4,6 items should select ,but 0,2,4,5 are selected why?
      }

*****My MXML:-*****
<mx:Button id="btn" label="Find Unmatch Nodes" width="221" height="30" click="select_tree()"/>



<mx:Tree id="tree"  right="10" top="54" bottom="10" width="49.5%" dataProvider="{XMLList}"
    fontFamily="Verdana" fontSize="11" showScrollTips="true"
    allowMultipleSelection="true"
    alternatingItemColors="[#F5F5F5]"
    labelField="@label" selectionColor="#ECF335" showRoot="false"/>

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

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

发布评论

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

评论(1

农村范ル 2024-12-20 15:13:37

通过将 tree.selectedIndices 设置为 allItems1 (而不是 allItems),您的代码中有一个错误。

tree.selectedIndices = allItems1;

为什么不直接创建一个 Bindable 数组,并将其设置为树的 selectedIndices 属性?

[Bindable]
public var selectedTreeValues:Array = new Array();

...

<mx:Tree id="tree"  right="10" top="54" bottom="10" width="49.5%" 
    dataProvider="{XMLList}"
    fontFamily="Verdana" fontSize="11" showScrollTips="true"
    allowMultipleSelection="true"
    alternatingItemColors="[#F5F5F5]"
    labelField="@label" selectionColor="#ECF335" showRoot="false"
    selectedIndices="selectedTreeValues"
/>

最后,跟踪它,而不必手动完成? Flex 的优点之一是能够利用 Binding 值。

You have a mistake in your code by setting tree.selectedIndices to allItems1 (instead of allItems).

tree.selectedIndices = allItems1;

Why don't you just created a Bindable Array, and have it set to the selectedIndices property of the tree?

i.e.

[Bindable]
public var selectedTreeValues:Array = new Array();

...

<mx:Tree id="tree"  right="10" top="54" bottom="10" width="49.5%" 
    dataProvider="{XMLList}"
    fontFamily="Verdana" fontSize="11" showScrollTips="true"
    allowMultipleSelection="true"
    alternatingItemColors="[#F5F5F5]"
    labelField="@label" selectionColor="#ECF335" showRoot="false"
    selectedIndices="selectedTreeValues"
/>

Finally, trace that out, instead of having to do it manually? One of the beauties of Flex is being able to leverage Binding values.

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