简体   繁体   English

奥雷利亚(Aurelia)重复

[英]Aurelia repeat.for for - some questions

I am attempting to generate a form like this: 我正在尝试生成这样的表格:

<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>

where config is a variable in my view-model. 其中config是我的视图模型中的变量。

A couple questions: 几个问题:

1) I have tried both for.repeat="field in ${config.formMain}" and for.repeat="field in config.formMain" and neither syntax seems to work. 1)我已经尝试了for.repeat="field in ${config.formMain}" for.repeat="field in config.formMain"for.repeat="field in config.formMain" ,但两种语法似乎都不起作用。 How am I meant to access the array from the object? 我如何从对象访问数组?

2) Is there any support for something like for.repeat.one-time="field in ${config.formMain}" where this would cause Aurelia to only execute the loop compilation once (which is useful in my case because the form is not going to chage) but keep the bindings inside the loop as default bindings (ie if I have a for.repeat inside of the outer one, it should update itself if the array it is iterating over changes)? 2)是否for.repeat.one-time="field in ${config.formMain}"这样的for.repeat.one-time="field in ${config.formMain}"有任何支持,这将导致Aurelia仅执行一次循环编译(这在我的情况下非常有用,因为表单是不会破坏),但将循环内的绑定保留为默认绑定(即,如果我在外部的内部有一个for.repeat,如果它要遍历更改的数组,它应该更新自身)?

Thanks in advance. 提前致谢。

The correct syntax is: repeat.for="thing of things" 正确的语法是: repeat.for =“事物”

See that is of instead of in , following the ECMAScript 6 style. 请参阅 ,而不是继6 ECMAScript的风格。 More information at https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of 有关更多信息, 请参见https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of

You could use "& oneTime" to execute the loop only once. 您可以使用“&oneTime”仅执行一次循环。 Like this: 像这样:

repeat.for="thing of things & oneTime"

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

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