范围:
let bases = [{id: "51667c34ed4dd", name: "CAYENNE", sort: 1}, {id: "516682b6a160e", name: "FORT DE FRANCE", sort: 2}, {id: "516682c230fbb", name: "POINT A PITRE", sort: 3}];
let filters = {bases: {51667c34ed4dd: true, 516682b6a160e: false, 516682c230fbb: true}, aircrafts: {}};
let set = {bases, filters};
模板:
{{#bases}}
<input type="checkbox" class="base_checkbox" value="1" id="{{id}}" name="{{name}}" {{(if checked)}}checked="checked"{{/(if checked)}}>
{{/bases}}
用法:
Mustache.render(template, set);
在{{#bases}}
循环中,如何以当前范围属性作为键访问另一个外部对象值?
喜欢:{{filters.bases {{id}} }}其中{{id}}是循环中当前对象的属性。
答案 0 :(得分:0)
已解决:
bases.forEach(b => {
b.checked = () => {
return filters["bases"][b.id];
}
});
Mustache使用函数返回值作为变量。