Hi Chen,
this should work for you.
Changes:
- using "toggleselected" on the list
- using a handler to listen for "onselected" events from the list to
disable/enable delete btn
- using "getNumItems" and "getItemAt" to retrieve the list items
---
<canvas height="550" debug="true">
<simplelayout spacing="10"/>
<dataset name="dsMyWishList">
<wishes>
<wish>Constraints are wonderful but I wish they work</wish>
<wish>I can retrieve list elements</wish>
</wishes>
</dataset>
<list id="mylist" width="200" height="82" toggleselected="true" >
<textlistitem datapath="dsMyWishList:/wishes/wish/text()" />
</list>
<button text="Delete" enabled="false" >
<handler name="onselect" reference="mylist" >
this.setAttribute("enabled", mylist.getSelection() != null);
</handler>
</button>
<button text="Test">
<handler name="onclick"><![CDATA[
Debug.write("Number of subviews: ", mylist.getNumItems());
for (var i = 0; i < mylist.getNumItems(); ++i) {
Debug.write("The element: ", mylist.getItemAt(i));
}
]]></handler>
</button>
</canvas>
---
Hi There,
I am trying to use the list component in my GUI. After a day of struggling, I guess I have to seek help from the professionals.
First of all, I need to retrieve all the elements from the list, but found no way to get them (unless I program it myself). Tried to use the 'subviews' array but it does not seem giving me what I wanted. I am wondering whether there is an easy way to get the elements of a list.
Second, I am trying to use the constraint between a "Delete" button and the selectionmanager so that the delete button will be enabled if and only if there is one selection on the list. But, it does not seem working.
Below is the simplified code.
Your help is greatly appreciated!
Chen Ding
================ Example ==============================
1 <canvas height="550" debug="true">
2 <simplelayout spacing="10"/>
3 <dataset name="dsMyWishList">
4 <wishes>
5 <wish>Constraints are wonderful but I wish they work</wish>
6 <wish>I can retrieve list elements</wish>
7 </wishes>
8 </dataset>
9
10 <list id="mylist" width="200" height="82">
11 <selectionmanager name="selector" toggle="true"/>
12 <textlistitem datapath="dsMyWishList:/wishes/wish/text()"
onclick="mylist.selector.select(this)"/>
13 </list>
14
15 <simplelayout axis="y"/>
16
17 <!-- Wish 1: use the constraint to enable/disable the delete button. The button indeed -->
18 <!-- was disabled initially, but is never enabled even when I
selected an -->
19 <!-- in the list.
-->
20 <button text="Delete" enabled="${mylist.selector.selected == 1}"/>
21
22 <!-- Wish 2: can retrieve list elements. The only way I can find is through 'subviews' -->
23 <!-- but it does not seem working
-->
24 <button text="Test">
25 <handler name="onclick">
26 <![CDATA[
27 Debug.write("Number of subviews: ", mylist.subviews.length);
28 for (var i=0; i<mylist.subviews.length; i++)
29 {
30 Debug.write("The element: ", mylist.subviews[i]);
31 }
32 ]]>
33 </handler>
34 </button>
35 </canvas>
This message is confidential to Prodea Systems, Inc unless otherwise indicated
or apparent from its nature. This message is directed to the intended recipient
only, who may be readily determined by the sender of this message and its
contents. If the reader of this message is not the intended recipient, or an
employee or agent responsible for delivering this message to the intended
recipient:(a)any dissemination or copying of this message is strictly
prohibited; and(b)immediately notify the sender by return message and destroy
any copies of this message in any form(electronic, paper or otherwise) that you
have.The delivery of this message and its information is neither intended to be
nor constitutes a disclosure or waiver of any trade secrets, intellectual
property, attorney work product, or attorney-client communications. The
authority of the individual sending this message to legally bind Prodea Systems
is neither apparent nor implied,and must be independently verified.