【问题标题】:Aurelia repeat.for for - some questionsAurelia repeat.for for - 一些问题
【发布时间】:2016-03-18 03:54:31
【问题描述】:

我正在尝试生成这样的表单:

<div class="col-xs-6" for.repeat="field in ${config.formMain}">
                        <div class="form-group">
                            <label>${field.label & oneTime}</label>
                            <select if.one-time="field.controlType == 'select'" class="form-control">
                                <option value=""><- Select -></option>
                            </select>
                        </div>
                    </div>

config 是我的视图模型中的一个变量。

几个问题:

1) 我尝试了for.repeat="field in ${config.formMain}"for.repeat="field in config.formMain",但两种语法似乎都不起作用。我的意思是如何从对象访问数组?

2) 是否支持 for.repeat.one-time="field in ${config.formMain}" 这样的东西作为默认绑定(即,如果我在外部有一个 for.repeat,如果它迭代的数组发生变化,它应该自我更新)?

提前致谢。

【问题讨论】:

    标签: javascript aurelia


    【解决方案1】:

    正确的语法是:repeat.for="thing of things"

    请看这是 of 而不是 in,遵循 ECMAScript 6 风格。更多信息https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of

    您可以使用“& oneTime”只执行一次循环。像这样:

    repeat.for="thing of things & oneTime"
    

    【讨论】:

      猜你喜欢
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      相关资源
      最近更新 更多