加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何使用angularjs从表中获取行数据

发布时间:2020-12-17 17:31:23 所属栏目:安全 来源:网络整理
导读:我是 angularjs的新手.我正面临一个问题.我有一个带一个单选按钮的桌子.当用户选择任何单选按钮并单击提交按钮时,我需要显示所选行的详细信息. Html代码: table thead tr thSelect/th thFirst Name/th thLast Name/th thUnique Reference ID/th thCountry/t
我是 angularjs的新手.我正面临一个问题.我有一个带一个单选按钮的桌子.当用户选择任何单选按钮并单击提交按钮时,我需要显示所选行的详细信息.

Html代码:

<table>
    <thead>
        <tr>
            <th>Select</th> 
            <th>First Name</th> 
            <th>Last Name</th> 
            <th>Unique Reference ID</th> 
            <th>Country</th> 
            <th>Branch</th> 
            <th>Card No</th> 
       </tr>
    </thead>

    <tr ng-repeat="d in Employees">
        <td><input type="radio"></td>
        <td>{{d.fname}}</td>
        <td>{{d.lname}}</td>
        <td>{{d.uniqueid}}</td>
        <td>{{d.country.name}}</td>
        <td> {{d.branch.name}}</td>
        <td>{{d.cardno}}</td> 
    </tr>
</table>

<table>
    <tr>
        <td><input type="button" value="Edit" ng-click="Edit()"></td>
    </tr>
</table>

控制器代码:

$scope.Edit=function()
{
    //need id of selected row ?
};

解决方法

像这样的东西:

<input type="radio" ng-click="editData.employee = d">

和控制器:

$scope.editData = {};

$scope.Edit = function() {
  var id = $scope.editData.employee.id;
};

我刚刚回答了另一个关于它如何影响你的代码的问题,ng-repeat为每个列表项创建了一个新的范围,这就是为什么你需要editData对象才能工作的原因.它可以帮助您理解为什么需要它:Angular replace data from ng-repeat item

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读