0

我试图使它成为可能,以便通过单击以下之一中的“客户端”,<td>我可以从“客户端”数组中选择该特定对象并切换到新视图。我想我想从 ng-click 开始,只是不知道该怎么做。此外,我不会使用任何 jquery。

<div ng-init="clients = [
    {firstname:'Buster', lastname:'Bluth', tagid:'4134'},
    {firstname:'John', lastname:'McClane', tagid:'9845'},
    {firstname:'Mister', lastname:'Spock', tagid:'0905'}
    ]"></div>
<div>
    <div>Clients</div>
        <table>
            <thead>
                <tr>
                     <th>First Name</th>
                     <th>Last Name</th>
                     <th>I-Number</th>
                </tr>
                </thead>
                <tbody>
                   <tr ng-repeat="client in clients">
                       <td>{{client.firstname}}</td>
                       <td>{{client.lastname}}</td>
                       <td>{{client.inumber}}</td>
                   </tr>
                </tbody>
            </table>
        </div>
4

1 回答 1

2

ng-click是正确的做法。您可以像这样获取选定的对象

<tr ng-repeat="client in clients" ng-click="redirect(client)">

使用以下方法创建控制器:

function ctrl($scope, $location){
    $scope.redirect = function(client){
        console.log(client);
        $location.url('/someurl'); //this is the routing defined in the $routingProvider, you need to implement it.
    }
}

确保您引用包含这样选择的外部 div 中的类

<div ng-controller='ctrl'>
于 2013-08-20T19:43:18.493 回答