我正在使用 Aurelia 创建一个 Web 应用程序。 (http://aurelia.io/)。 我需要将函数参数从 HTML View 传递到 Controller 。这是我的 HTML 代码。
<table class="table table-bordered">
<thead>
<tr>
<th>Full Name</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr repeat.for="user of users">
<td>
${user.fullname}
<div id="${user.oid}" class="collapse">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
</td>
<td>
<a href="#${user.oid}" click.delegate="select($user)" data-toggle="collapse"
class="btn btn-primary btn-xs">View</a>
</td>
</tr>
</tbody>
</table>
在此代码中,您可以看到该函数的参数为“$user”。
click.delegate="select($user)"
我需要从 Controller 访问此用户对象,就像我在 Controller 中所做的那样。但它不起作用并给我带来未定义的错误。
select(user) {
console.log(user);
}
当我打印用户对象时,它是未定义的。那么你能告诉我如何解决这个问题吗?如果我无法传递整个用户对象,请告诉我一种传递单个值(如“user.fullname”)的方法。这样也好。
谢谢:)
最佳答案
执行以下更改:
click.delegate="select(user)"
关于javascript - 如何将函数参数从 Aurelia View 传递到 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45073689/