PolymerElements / iron-selector

Manages a list of elements that can be selected
32 stars 55 forks source link

wrong selected value when use dom-repeat #82

Open duongphuhiep opened 8 years ago

duongphuhiep commented 8 years ago

I use iron-selector on a dom-repeat a list of item

First I set the selected value to foo then set the list to ["bar", "foo"] and I saw foo is selected as expected. But then, I set the list to ["foo", "rock"], the selected value is always foo, but now the real selected node is rock, not foo. So the selected value is no longer tells the real selected node.

<dom-module id="repeat-list">
    <template>
        <style>
            .iron-selected {
                background: yellow;
            }
        </style>
        <ul>
        <iron-selector selected-items="{{selectedItems}}"
                       attr-for-selected="someAttr"
                       selected="{{valueSelected}}">
            <template id="repeater" is="dom-repeat" items="{{list}}">
                <li some-attr={{item}}>{{item}}</li>
            </template>
        </iron-selector>
        </ul>
        First selected item: <span>{{selectedItems.0}}</span><br/>
        Value selected: <span>{{valueSelected}}</span>
    </template>

    <script>
        Polymer({
            is: "repeat-list",
            properties: {
                list: Array,
                selectedItems: Array,
                valueSelected: {
                    type: String,
                    notify: true
                }
            },
            ready: function() {
                this.valueSelected="foo";

                var _this = this;
                setTimeout(function(){
                    _this.list = ["bar", "foo"]; //ok, foo is selected
                }, 1000);

                setTimeout(function(){
                    _this.list = ["foo", "rock"]; //ko! valueSelected="foo" but "bar" item is selected
                }, 2000);
            }
        });
    </script>
</dom-module>
hedcet commented 8 years ago

iron-selector not updates its selection on dom repeat items when data change, i tested it in polymer gmail @ebidel example that app fails to update selected property to child element

cdata commented 8 years ago

Please re-open this issue with a JSBin demonstrating the problem! For more details on filing issues, you can refer to our contributing guidelines.

duongphuhiep commented 8 years ago

Hello,

I demonstrated the problem in plunker:

http://plnkr.co/edit/dqSFV2XQ6x1UjJdm7fFl?p=preview

is it ok? do I have to open a new issue or reuse this one?

hedcet commented 8 years ago

:+1: you r the bro bro