2
因此,我有一個viewModel中需要訪問每個元素的對象列表。我嘗試使用element.ref
,但對象中沒有元素。在Aurelia中添加對重複項的元素引用
persons.js
export class PersonsViewModel {
persons = [{
id: 0,
name: 'Matt'
}]
// this function fails, person.el is undefined
increase(person) {
person.el.style.height = person.el.clientHeight + 10;
person.el.style.width = person.el.clientWidth + 10;
}
}
persons.html
<template>
<div repeat.for="person of persons" element.ref="el">
<div>${person.name}</div>
<button click.delegate="increase(person)">+</button>
</div>
</template>