[英]How to pass function parameters from Aurelia view to controller?
I'm creating a web application using Aurelia. 我正在使用Aurelia创建一个Web应用程序。 ( http://aurelia.io/ ).
( http://aurelia.io/ )。 I need to pass function parameters from HTML view to controller.
我需要将函数参数从HTML视图传递到控制器。 Here's my HTML code.
这是我的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>
In this code, you can see this function with parameter of '$user'. 在此代码中,您可以看到此函数的参数为'$ user'。
click.delegate="select($user)"
click.delegate = “选择($用户)”
I need to access this user object from the controller as I have done in the controller. 正如我在控制器中所做的那样,我需要从控制器访问此用户对象。 But it's not working and get me undefined error.
但它不起作用,并得到我未定义的错误。
select(user) {
console.log(user);
}
When I print the user object, it's undefined. 当我打印用户对象时,它是未定义的。 So can you tell me how to fix this please ?
那你能告诉我如何解决这个问题吗? If I can't pass the whole user object, tell me a way to pass one single value like 'user.fullname'.
如果无法传递整个用户对象,请告诉我一种传递单个值(如“ user.fullname”)的方法。 That would also be fine.
那也可以。
Thanks :) 谢谢 :)
进行以下更改:
click.delegate="select(user)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.