gpt4 book ai didi

javascript - 从外部 ng-repeat 获取值

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

如何从 ng-repeat 外部获取值?这是我从 json 获取值的函数

function($scope, $http) {
$http.get('https://www.mywebsite.com/images/getimages.php').
success(function(data, status, headers, config) {
$scope.walls = data.walls;
console.log($scope.walls);
}).error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});

然后我有一张 table :

<tr ng-repeat="wall in walls">
<td>{{wall.id}}</td>
<td><a href="#" ng-click="">{{wall.link}}</a></td>
</tr>

i 将显示在表格外的 div 中,因此在 ng-repeat 之外,{{wall.link}} 从 td 中选择。我该怎么做?

最佳答案

您可以实现 Controller 功能来设置选定的墙对象:

function ($scope, $http) {

$http.get('https://www.mywebsite.com/images/getimages.php')
.success(function (data, status, headers, config) { /*...*/ })
.error(function (data, status, headers, config) { /*...*/ });

$scope.select = function (wall) {
$scope.selectedWall = wall;
};
}

以及您将使用的 HTML

<table>
<tr ng-repeat="wall in walls">
<td>{{wall.id}}</td>
<td>
<a href="#" ng-click="select(wall)">{{wall.link}}</a>
</td>
</tr>
</table>

<div>{{selectedWall.link}}</div>

关于javascript - 从外部 ng-repeat 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30290707/

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