简体   繁体   中英

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.

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. 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)?

Thanks in advance.

The correct syntax is: repeat.for="thing of things"

See that is of instead of in , following the ECMAScript 6 style. More information at https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of

You could use "& oneTime" to execute the loop only once. Like this:

repeat.for="thing of things & oneTime"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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