As far as I can tell, there is no way to get the index of a selected item in a list. Am I overlooking something?

No, there's no nice way to do it. You can set the value attribute of your listitems to a useful number (say, the offset in the list). Or you can blindly hack at list:

<canvas debug="true">

    <class name="hacklist" extends="list">
        <method name="getItemOffset" args="li">
            <![CDATA[
            var sv = li.immediateparent.subviews;
            for ( var i = 0; i < sv.length; i++ ) {
                if ( li == sv[i] ) return i;
            }
            return NaN;
            ]]>
        </method>
    </class>

    <simplelayout axis="x"/>

    <hacklist name="l">
        <listitem selected="true">
            <text text="zero"/>
        </listitem>
        <listitem>
            <text text="one"/>
        </listitem>
        <listitem>
            <text text="two"/>
        </listitem>
    </hacklist>

    <button text="print offset">
        <method name="print" event="onclick">
Debug.write( canvas.l.getItemOffset( canvas.l.getSelection() ) );
        </method>
    </button>

</canvas>

Dan Stowell
Software Engineer
Laszlo Studios

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to