我是一些模板,我有时会使用repea.for
。当我试图将数据绑定到<editable-file-upload>
组件内的可绑定变量时,会出现问题。
我希望像<editable-file-upload elem-id.bind="${elem.parent.id}">Upload</editable-file-upload>
一样传递它,但会收到错误 - aurelia-logging-console.js:54 ERROR [app-router] Error: Parser Error: Missing expected : at column 7 in [${elem.parent.id}]
。如果我传递了它,<editable-file-upload elem-id.bind="elem.parent.id">Upload</editable-file-upload>
值为undefined
。但它不可能是未定义的,因为在div.files-wrapper
内部,我可以选择那些值并看到正确的值。怎么通过呢?我无法理解。
<div class="row">
<div class="col-md-12">
<div class="panel-group" id="someid" role="tablist" aria-multiselectable="true">
<div class="panel panel-default" repeat.for="elem of elems">
<div class="panel-heading" role="tab" id="${elem.parent.id}-heading">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#elems" href="#${elem.parent.id}" aria-expanded="false" aria-controls="#${elem.parent.id}">
<i class="glyphicon glyphicon-triangle-right"></i>${elem.parent.kood}
</a>
</h4>
</div>
<div id="${elem.parent.id}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="${elem.parent.id}-heading">
<div class="panel-body">
<div class="elem" if.bind="!elem.children.length">
<div class="files-wrapper">
<div class="files-message">Toimingul ei ole veel malle.</div>
<editable-file-upload elem-id.bind="${elem.parent.id}">Upload</editable-file-upload>
</div>
</div>
<div class="sub_elems" if.bind="elem.children.length">
<div class="sub_elem" repeat.for="subElems of elem.children">
<div class="sub_elem-title">${subElem.kood}</div>
<div class="files-wrapper">
${elem.parent.id}
${subElem.id}
<div class="files-message">Some text</div>
<editable-file-upload elem-id.bind="${elem.parent.id}" sub-elem-id.bind="${subElem.id}">Lae üles</editable-file-upload>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
您在repeat.for
内,并且您要访问的属性属于父范围。因此,您必须使用$parent
关键字来访问父作用域,然后访问该属性。例如:
<div class="files-wrapper">
${$parent.elem.parent.id}
${subElem.id}
<div class="files-message">Some text</div>
<editable-file-upload elem-id.bind="$parent.elem.parent.id"
sub-elem-id.bind="subElem.id">
Lae üles
</editable-file-upload>
</div>
</div>