简体   繁体   English

聚合物铁选择器使dom.repeat中的this.push()混乱

[英]polymer iron-selector messing up this.push() in dom-repeat

I have a strange problem where I have a div table filled by dom-repeat where I am using an iron-selector to pick entries from that table. 我有一个奇怪的问题,我有一个由dom-repeat填充的div表,在这里我正在使用iron-selector从该表中选择条目。 However the arrays I'm pushing to don't appear in the correct order when I have something selected in the iron-selector. 但是,当我在熨斗选择器中选择了某些东西时,我要推入的数组不会以正确的顺序出现。 Is this just some subtle thing about how the selector is supposed to work, that I'm misunderstanding? 这是我误会的关于选择器应该如何工作的一些微妙的东西吗? Do I have to unassign the selected value every time I want to push to the array properly? 每次我要正确推送到数组时,是否都必须取消分配selected值?

Here's the code for the table and the selector: 这是表和选择器的代码:

<iron-selector  selected="{{selItem}}">        
  <template is="dom-repeat" items="{{dirs}}">
     <div class="row" name="{{item.name}}">
       <div class="item">
         <a is="app-link" path="{{item.url}}" href="{{item.url}}">
         <dir-item kind="folder">{{item.name}}</dir-item>
         </a>
       </div>
      <div class="item"> value</div>
    </div>
  </template>
  <template is="dom-repeat" items="{{keys}}">
    <div class="row" name="{{item.name}}">
      <div class="item">
        <dir-item kind="key">{{item.name}}</dir-item>
      </div>
      <div class="item">
        <span class="paper-font-body1">{{item.value}}</span>
      </div>
    </div>
  </template>
</iron-selector> 

EDIT: I have to splice everything out of the array before trying to push for the problem to occur. 编辑:我必须试图将所有问题从阵列中splice出来,然后再尝试推动问题发生。

the problem is roughly if I do this.push('dirs', foo); 问题大概是如果我这样做this.push('dirs', foo); or this.push('keys', foo); this.push('keys', foo); with something on this table selected, that is if this.selItem is assigned, foo doesn't appear in the place in the table where I expect it. 选择此表上的某些内容,即如果已分配this.selItem ,则foo不会出现在我期望的表中的位置。 More troubling, when an app-link is clicked, it basically retrieves information from a server that is rendered on this table, which shows up bizarre if something was selected, if not it renders fine. 更麻烦的是,当单击app-link ,它基本上是从此表上呈现的服务器中检索信息,如果选择了某些内容,它会显得很奇怪,否则,它会很好地呈现。

Should I be un-assigning selItem to avoid this? 我应该取消分配selItem以避免这种情况吗? If so, what is the appropriate way to do this? 如果是这样,执行此操作的适当方法是什么?

EDIT, if I completely remove the iron-selector tags, the dom-repeat rendering of the array behaves how I want it, regardless of how I splice or push to the contained elements. 编辑,如果我完全删除了iron-selector标签,则无论我如何splicepush入所包含的元素,该数组的dom-repeat渲染都将按照我的期望进行操作。 Am I just using iron-selector in a dumb way? 我只是在愚蠢地使用选iron-selector吗?

Thanks, 谢谢,

You should be able to put multiple dom-repeats in an <iron selector> . 您应该能够将多个dom重复放入<iron selector> It works for me in my test here: 在我的测试中,它对我有用:

iron-selector#1.0.2 铁选择器#1.0.2

polymer#1.0.8 聚合物#1.0.8

<dom-module id="x-app">

  <style>

    :host {
      display: block;
    }

    button {
      padding: 8px;
      margin: 16px;
    }

    iron-selector {
      display: block;
      border: 1px solid #ccc;
      border-top: none;
    }

    .row {
      padding: 16px;
      border-top: 1px solid #ccc;
    }

    .row.iron-selected {
      background-color: #ccc;
    }

  </style>

  <template>

    <button on-tap="testSpliceAndPush">Test Splice And Push</button>

    <iron-selector attr-for-selected="name" selected="{{selected}}">
      <template is="dom-repeat" items="{{aItems}}">
        <div class="row" name="{{item.name}}">{{item.name}}</div>
      </template>
      <template is="dom-repeat" items="{{bItems}}">
        <div class="row" name="{{item.name}}">{{item.name}}</div>
      </template>
    </iron-selector>

  </template>

  <script>

    Polymer({

      is: 'x-app',

      ready: function() {
        this.aItems = [{name: 'a0'}, {name: 'a1'}, {name: 'a2'}];
        this.bItems = [{name: 'b0'}, {name: 'b1'}, {name: 'b2'}];
      },

      testSpliceAndPush: function() {
        this.splice('aItems', 0, this.aItems.length);
        this.splice('bItems', 0, this.bItems.length);

        for (var i = 0; i < 4; i++) {
          this.push('aItems', {name: 'a' + i});
        }

        for (var i = 0; i < 5; i++) {
          this.push('bItems', {name: 'b' + i});
        }
      }

    });

  </script>

</dom-module>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM