我认为它应该是人们处理它的一种常见模式,但我很惊讶为什么我在互联网上找不到任何东西。角度简单选择问题
可以说我有对象数组,并且我想在打开窗口中为客户显示这些对象。当顾客选择某件事情时,我想记住顾客的选择并进一步处理。
问题:客户可读的格式显示的所有项目 - item.name
(伦敦,里斯本,曼彻斯特)当客户选择的东西,我ng-model
fromSelected
等于只是城市串名字,这意味着什么对我来说,因为我还需要id
进一步处理。
您能否建议我如何让fromSelected
等于对象而不是字符串,但同时为用户提供友好的输出?
var app = angular.module("fly");
app.controller('PlaceController', function($scope) {
$scope.fromSelected ='';
$scope.getPlace = function() {
var items = []
items.push({
'id': 1,
'name': London
});
items.push({
'id': 2,
'name': Lisbon
});
return items;
};
});
HTML:
<input type="text" ng-model="fromSelected" placeholder="Country, city or airport" typeahead="place.name for place in getPlace()" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
你'fromSelected'将有''放置所选对象..你可以简单地做'fromSelected.id' –