我在列表中迭代了一个对象数组。如果我点击名称,它应该提醒我名字对应的城市的价值。
<div ng-app='myApp'>
<div ng-controller="AppController">
<div ng-click="getCity()" ng-repeat="step in steps">
<p> {{step.name}}</p>
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.controller('AppController', function ($scope) {
$scope.steps = [
{name: "ABC", status: true, city: "Boston"},
{name: "DEF", status: true, city: "New York"},
{name: "GHI", status: true, city: "LA"}
];
$scope.getCity = function(a) {
}
});
- &GT;所以我点击&#34; ABC&#34;和#34;波士顿&#34;应该向我展示。
感谢帮助。感谢。
答案 0 :(得分:2)
您可以将值传递给getCity
函数:
var myApp = angular.module('myApp', []);
myApp.controller('AppController', function($scope) {
$scope.steps = [{
name: "ABC",
status: true,
city: "Boston"
},
{
name: "DEF",
status: true,
city: "New York"
},
{
name: "GHI",
status: true,
city: "LA"
}
];
$scope.getCity = function(step) {
alert(step.city)
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp'>
<div ng-controller="AppController">
<div ng-click="getCity(step)" ng-repeat="step in steps">
<p> {{step.name}}</p>
</div>
</div>
</div>
&#13;