gpt4 book ai didi

javascript - 如何使用 Angular JS 更新表中的值

转载 作者:行者123 更新时间:2023-11-29 11:13:03 24 4
gpt4 key购买 nike

我正在使用 PHP/MySQL/Socket.IO/NodeJS。我正在尝试扩展我的网站并为其添加更多功能。本质上,当新用户添加到表中时,我需要更新表,但我很确定我需要使用 AngularJS 来完成此操作。

<pre>
<thead>
<tr>
<th>Name</th>
<th>Risk</th>
</tr>
</thead>
<tbody>
<tr><td> Joe </td> <td> 5 </td>
</tbody>

正如您所看到的,Joe 的“风险”值为 5,这可能会因一些不同的因素而改变。我需要知道当使用 AngularJS 调用套接字事件时更改 Joe 的值的方法,或者是否有其他更容易工作的方法。

最佳答案

您有一个包含数据的 JavaScript 模型,当您更新数据时, View 将相应更新。传入套接字后,您只需更新 $scope.users。

在你的 Controller 中:

$scope.users = [
{ name: 'Joe', risk: 5 }
];

在您的模板中:

 <thead>
<tr>
<th>Name</th>
<th>Risk</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>{{ user.name }}</td>
<td>{{ user.risk }}</td>
</tbody>

关于javascript - 如何使用 Angular JS 更新表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40201441/

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