您好我有以下数据
var myApp = angular.module('myApp', [])
.controller('TestController', ['$scope', function ($scope) {
$scope.data = [{"city":"New York","location":"123", "sales" :"233.00"},
{"city":"Chicago","location":"953", "sales":"455"}'
{"city":"New York","location":"788", "sales" :"23432.23"},
{"city":"Chicago","location":"853"}];
$scope.update=function(location){
};
}]);
在我的HTML中我有
<td>
<select ng-model="item.location" ng-options="c.location as c.city for c in data"
ng-change="update(c.location)"></select>
</td>
<td>
<div>
<span ng-model="item.sales">{{sales }} </span>
</div>
</td>
我正在尝试从选定的下拉值调用更新功能,并根据所选项目我想使用span更新销售价值。我不知道如何完成这一部分。请让我知道如何去做。谢谢
答案 0 :(得分:1)
您甚至不需要更新功能,只需使用数据绑定。更改这样的ng-options以绑定整个对象而不仅仅是字段location
:
ng-options="c as c.city for c in data"
要显示销售额,请执行以下操作:
<span>{{ item.location.sales }} </span>