您好,我有以下数据
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>
我正在尝试从下拉列表的选定值中调用更新函数,并根据所选的项目,我想使用跨度更新销售值。我不知道如何完成那部分。请让我知道该怎么做。谢谢
最佳答案
您甚至不需要更新功能,只需使用数据绑定(bind)即可。像这样更改您的 ng-options 以绑定(bind)整个对象,而不仅仅是一个字段 location
:
ng-options="c as c.city for c in data"
要显示销售额,只需执行以下操作:
<span>{{ item.location.sales }} </span>
关于javascript - 根据 Angularjs 中选定的值显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22727655/