ianharrigan / haxeui

IMPORTANT NOTE! This repository is no longer maintained. Please consider the newer version: https://github.com/haxeui/haxeui-core
http://haxeui.org/
392 stars 46 forks source link

[QUESTION] How can you return a String from a selectedIndex in ListSelector? #336

Closed notalentgeek closed 8 years ago

notalentgeek commented 8 years ago

I am sorry if this inappropriate place to ask for.

I have a ListSelector that contains "Hello", "World!". For example I selected "Hello". When I do listSelectorObject.selectedIndex it returns 0. But what if I want to return "Hello" string instead of 0. Is there any possible way to do this?

For additional info, my listSelectorObject is actually inputted using dataSource.createFromString() from Array that is generated depend on another ListSelector value.

ianharrigan commented 8 years ago

There are a few options available: http://haxeui.org/try.jsp?layoutId=GzzRK5a

<?xml version="1.0" encoding="utf-8" ?>
<vbox>
    <script>
        function onChange1() { 
            log.text = myList1.text + ", ";
            log.text += myList1.selectedIndex + ", ";
            log.text += myList1.selectedItems[0].data.text + ", ";
        }

        function onChange2() { 
            log.text = myList2.text + ", ";
            log.text += myList2.selectedIndex + ", ";
            log.text += myList2.selectedItems[0].data.text + ", ";
            // this will work for json data, will be null otherwise
            log.text += myList2.selectedItems[0].data.something;
        }
    </script>

    <hbox>
        <listselector id="myList1" text="Select" width="100" onchange="onChange1()">
            <array>Hello,World</array>
        </listselector>
        <listselector id="myList2" text="Select" width="100" onchange="onChange2()">
            <json>
                [
                    {"text": "Hello", "something": "else1"},
                    {"text": "World", "something": "else2"}
                ]
            </json>
        </listselector>
    </hbox>
    <textinput width="200" height="100" id="log" multiline="true" />
</vbox>
notalentgeek commented 8 years ago

Exactly what I need thanks Ian!

However, http://haxeui.org/try.jsp is not working on Linux, Google Chrome. There is only Layout tab but no Result tab.

ianharrigan commented 8 years ago

Yeah, i think there are some flash issues... I think if you keep refreshing it works eventually (not totally sure), either way, eventually the whole haxeui.org is going to get a new version.

Glad it helped! Can this be closed?

notalentgeek commented 8 years ago

Yes just close this. Thank you!