gpt4 book ai didi

javascript - Aurelia 中的嵌套重复无法识别对象数组

转载 作者:行者123 更新时间:2023-11-29 10:36:12 25 4
gpt4 key购买 nike

使用 Aurelia,我有以下模型:

export class Services {
heading = 'Services';
services = [
{ 'name': 'Test Service', 'instances': [{'uri': 'test_uri'}]},
{ 'name': 'Another Service', 'instances': [{'uri': 'other_uri'}, {uri: 'backup_uri'}]}
];
}

和以下 View :

<template>

<require from="bootstrap/css/bootstrap.css"></require>

<div class="container">
<div class="row">
<div class="col-md-12">
<h2>${heading}</h2>
</div>
</div>

<div class="row" repeat.for="service of services">
<div class="panel panel-default">
<div class="panel-heading">${service.name}</div>
<table class="table">
<thead>
<tr>
<th>URI</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<div repeat.for="instance of service.instances">
<tr>
<td>${instance.uri}</td>
<td>Running</td>
</tr>
</div>
</tbody>
</table>
</div>
</div>
</div>

</template>

外层repeat.for似乎工作正常并且${service.name}替换为 .name来自模型的属性。然而,${instance.uri}不提供任何输出。如果我更换 ${instance.uri}${service.instances[0].uri}确实得到了预期的输出。

此外,我希望第二次重复 service of services在表体中生成两行,但它只生成一行。

我试过替换 <div repeat.for="instance of service.instances"><div repeat.for="instance of $parent.instances">同样令人不满意的结果。

我需要更改什么以确保内部重复正常工作?

最佳答案

浏览器不允许在表格中使用 div。

改变这个:

<tbody>
<div repeat.for="instance of service.instances">
<tr>
<td>${instance.uri}</td>
<td>Running</td>
</tr>
</div>
</tbody>

为此:

<tbody>
<tr repeat.for="instance of service.instances">
<td>${instance.uri}</td>
<td>Running</td>
</tr>
</tbody>

关于javascript - Aurelia 中的嵌套重复无法识别对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35997819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com