Polymer 熨斗列表在刷新时保持选择突出显示

Polymer 熨斗列表在刷新时保持选择突出显示,polymer,Polymer,我试图在刷新时保持选中的项目高亮显示,但我只能存储它,刷新时不呈现选中的项目 <iron-localstorage name="selectedItem" value="{{selectedItem}}"></iron-localstorage> <iron-list class="flex" items="{{data}}" as="item" selected-item="{{selectedItem}}" selection-enabled> 我删除了

我试图在刷新时保持选中的项目高亮显示,但我只能存储它,刷新时不呈现选中的项目

<iron-localstorage name="selectedItem" value="{{selectedItem}}"></iron-localstorage>
<iron-list class="flex" items="{{data}}" as="item" selected-item="{{selectedItem}}" selection-enabled>

我删除了所有我以前犯过的错误,因为这是一场白费力气的追逐,并没有考虑到铁名单中实际上并没有跟踪到的一堆东西。我在这里创建了一个JSBin示例:

问题的主要症结在于,此时iron list中没有跟踪selectItem()函数的更改事件,并且在对象而不是索引中跟踪selectedItem。也许,根据您的Github问题,出于这个原因,应该将selected添加为索引。因此,我认为在PR中应该有一个更全面的版本来为组件添加一些有价值的功能。然而,由于您需要将这两个元素包装在某种父元素中,这并不太粗糙

在这里,我捕获selectedItem更改事件,并使用该点的数据处理所选索引,将其保存到iron localstorage的值中。然后,当有东西从localStorage中加载时,我使用该索引在iron列表中选择Item()

<template id="app" is="dom-bind">
    <iron-list items="{{data}}" as="item" selection-enabled on-selected-item-changed="saveSelected">
        <template>
            <div>{{item.name}}<template is="dom-if" if="{{selected}}"><span>{{index}}</span></template></div>      
        </template>
    </iron-list>
    <iron-localstorage name="ironListData" value="{{ironListData}}" on-iron-localstorage-load-empty="initializeDefaultValue" on-iron-localstorage-load="setSelected"></iron-localstorage>
</template>
<script>
  var app = document.querySelector('#app');
  app.data = [
    {
      name: 'First Element'
    },
    {
      name: 'Second Element'
    },
    {
      name: 'Third Element'
    }
  ];
  app.setSelected = function(ev) {
      document.querySelector('iron-list').selectItem(app.ironListData);
  }
  app.saveSelected = function(ev) {
    if (ev.detail.value !== null)
      app.ironListData = document.querySelector('iron-list').items.indexOf(document.querySelector('iron-list').selectedItem);
  }
</script>

{{item.name}{{index}
var-app=document.querySelector(“#app”);
app.data=[
{
名称:“第一个元素”
},
{
名称:“第二个元素”
},
{
名称:“第三元素”
}
];
app.setSelected=功能(ev){
document.querySelector('iron-list')。selectItem(app.ironListData);
}
app.saveSelected=功能(ev){
如果(ev.detail.value!==null)
app.ironListData=document.querySelector('iron-list').items.indexOf(document.querySelector('iron-list').selectedItem);
}

好的,我们来试试,ps,选定的项目呢,可以直接使用吗?嗯,它需要什么样的字符串?因为对象只包含行中的所有记录?没有索引或其他内容,也尝试直接将其设置为so
selected item=“0”
thanking:)将此引用到问题