Javascript 基于Angularjs中的选定值显示值
嗨,我有以下数据Javascript 基于Angularjs中的选定值显示值,javascript,angularjs,Javascript,Angularjs,嗨,我有以下数据 var myApp = angular.module('myApp', []) .controller('TestController', ['$scope', function ($scope) { $scope.data = [{"city":"New York","location":"123", "sales" :"233.00"}, {"city":"Chicago","location":"953", "sal
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更新销售值。我不知道如何完成那部分。请告诉我怎么办。谢谢您甚至不需要更新功能,只需使用数据绑定即可。像这样更改ng选项以绑定整个对象,而不是仅绑定一个字段
位置
:
ng-options="c as c.city for c in data"
要显示销售额,只需执行以下操作:
<span>{{ item.location.sales }} </span>
{{item.location.sales}