聚合物模板在 dom-if 中重复

polymer templates repeating in dom-if

进行了更改以使其更加清晰。

<template is="dom-repeat" items="{{survey.Questions}}">
  <template is="dom-if" restamp if="{{isFormat(item.Type, 'Single-Select')}}">
    <question-singleselect question="{{item}}" auth-Data="{{authData}}"></question-singleselect>
  </template>
  <template is="dom-if" restamp if="{{isFormat(item.Type,'Open-Ended'}}">
    <question-openended question="{{item}}" auth-Data="{{authData}}"></question-openended>
  </template>
  <template is="dom-if" restamp if="{{isFormat(item.Type,'Text Block'}}">
    <question-textblock question="{{item}}" auth-Data="{{authData}}"></question-textblock>
  </template>
  <template is="dom-if" if="{{[[}}isFormat(item.Type,'Numerical'}}">
    D: {{item.Type}}
    <question-numerical question="{{item}}" auth-Data="{{authData}}"></question-numerical>
  </template>
</template>

这是我的代码,添加了您的函数,将其设置为 true 或 false。

对于上面列出的每个元素,我有一种类型,所以一个包含 4 条记录的数组。

结果显示数组中的记录,但上面带有 dom-if 的模板显示每个元素中的每条记录。例如,数值类型的数据,将显示在上面显示的每个部分中,而不是隐藏它们。

在问题对象中,我们在调查中有不同类型的问题,但是当我们传入调查对象时,问题会以不同问题模板类型中的不同格式重复...也就是说....问题 1 将显示在问题类型 1(比如单选按钮)和问题类型 2(比如复选框)下,即使它在调查返回的 json 中被列为 type1。

我使用 dom-repeat 和 dom-if 是否正确?想知道我错过了什么。

Polymer 不支持绑定中的表达式。另见 How do I write condition in polymer1.0 with "dom-if"?

dom-repeat 没问题我猜想在没有看到代码的情况下可以说什么。