gpt4 book ai didi

twitter-bootstrap - 带 Angular 的可点击 Bootstrap 行

转载 作者:行者123 更新时间:2023-12-03 14:34:35 26 4
gpt4 key购买 nike

我有一张 table ,用 Bootstrap 设计。该表的内容是使用 Angular.js 填充的。如何使一行可点击,以便它调用范围内的函数?

以下代码对我不起作用(ng-click 部分):

table :

    <table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ingredient in ingredients" ng-click="setSelected({{$index}});">
<td>{{ ingredient.name }}</td>
<td>{{ ingredient.status }}</td>
</tr>
</tbody>
</table>

Controller :
$scope.setSelected = function(index) {
$scope.selected = $scope.ingredients[index];
console.log($scope.selected);
};

最佳答案

建议和fiddle :

<tr ng-repeat="ingredient in ingredients" ng-click="setSelected();">
<td>{{ ingredient.name }}</td>
<td>{{ ingredient.status }}</td>
</tr>

<script>
var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {

$scope.ingredients = [
{'name': 'potato'},
{'name': 'tomato'}
];

$scope.setSelected = function() {
$scope.selected = this.ingredient;
console.log($scope.selected);
};

}
</script>

关于twitter-bootstrap - 带 Angular 的可点击 Bootstrap 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17658454/

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