【发布时间】:2019-08-14 17:58:27
【问题描述】:
我想用 Aurelia 构建一个简单的自定义组件,允许用户输入一个或多个字符串。当有多个项目时,列表应为列表中的每个项目显示删除按钮。
我的问题是当列表中有多个项目时,列表的第一项不显示 删除 按钮。 This is how it looks
这是自定义列表组件的代码和 html:
查看
<template>
<div repeat.for="item of items">
<input type="text" value.bind="items[$index]">
<button click.delegate="remove($index)"
if.bind="hasMoreThanOne()">Remove</button>
</div>
<button click.delegate="add()">Add</button>
</template>
视图模型
export class List {
items: string[];
constructor() {
this.items = [];
this.add();
}
add() {
this.items.push("");
}
hasMoreThanOne() {
return this.items.length > 1;
}
remove(index) {
this.items.splice(index,1);
}
}
我的问题有两个:
- 为什么当列表长度改变时第一个列表项没有自动更新?
- 如何使第一个项目也显示删除按钮?
【问题讨论】:
标签: aurelia