iron-selector icon indicating copy to clipboard operation
iron-selector copied to clipboard

wrong selected value when use dom-repeat

Open duongphuhiep opened this issue 10 years ago • 4 comments

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>

duongphuhiep avatar Nov 01 '15 23:11 duongphuhiep

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

hedcet avatar Jan 07 '16 12:01 hedcet

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

cdata avatar Jan 30 '16 01:01 cdata

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?

duongphuhiep avatar Jan 30 '16 23:01 duongphuhiep

:+1: you r the bro bro

hedcet avatar Feb 11 '16 18:02 hedcet