作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何从 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/
我是一名优秀的程序员,十分优秀!