Aurelia 对象的嵌套重复
Aurelia Nested repeats of objects
内部重复是否可以访问外部重复的值,具体如何?
这是我正在试验的一个例子:
this.headers = [
{text: 'Head 1', value: 'Col1'},
{text: 'Head 2', value: 'Col2'},
{text: 'Head 3', value: 'Col3'},
];
this.tableData = [
{'Col1': 1.1, 'Col2': 1.2, 'Col3': 1.3},
{'Col1': 2.1, 'Col2': 2.2, 'Col3': 2.3},
{'Col1': 3.1, 'Col2': 3.2, 'Col3': 3.3},
{'Col1': 4.1, 'Col2': 4.2, 'Col3': 4.3},
];
tableData
是根据headers
动态生成的
<table class="table table-striped">
<thead>
<tr>
<th repeat.for="head of headers">${head.text}</th>
</tr>
</thead>
<tbody>
<tr repeat.for="line of tableData">
<td repeat.for="head of $parent.headers">
${$parent.line[head.value]}
</td>
</tr>
</tbody>
</table>
我得到的都是空的table body
<table class="table table-striped">
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
我做错了什么????
奇怪。我设置了一个 plunkr 来调查,但它似乎像你上面粘贴的那样工作。
内部重复是否可以访问外部重复的值,具体如何? 这是我正在试验的一个例子:
this.headers = [
{text: 'Head 1', value: 'Col1'},
{text: 'Head 2', value: 'Col2'},
{text: 'Head 3', value: 'Col3'},
];
this.tableData = [
{'Col1': 1.1, 'Col2': 1.2, 'Col3': 1.3},
{'Col1': 2.1, 'Col2': 2.2, 'Col3': 2.3},
{'Col1': 3.1, 'Col2': 3.2, 'Col3': 3.3},
{'Col1': 4.1, 'Col2': 4.2, 'Col3': 4.3},
];
tableData
是根据headers
<table class="table table-striped">
<thead>
<tr>
<th repeat.for="head of headers">${head.text}</th>
</tr>
</thead>
<tbody>
<tr repeat.for="line of tableData">
<td repeat.for="head of $parent.headers">
${$parent.line[head.value]}
</td>
</tr>
</tbody>
</table>
我得到的都是空的table body
<table class="table table-striped">
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
我做错了什么????
奇怪。我设置了一个 plunkr 来调查,但它似乎像你上面粘贴的那样工作。