gpt4 book ai didi

javascript - AngularStrap typeahead ng-options - 与模型不同的标签

转载 作者:行者123 更新时间:2023-11-29 19:32:13 25 4
gpt4 key购买 nike

我正在为某些地址使用 AngularStrap typeahead。我想将选定的地址对象分配给我的 ng-model,但是当我这样做时,我失去了仅将对象属性之一显示为标签的选项。

示例返回对象:

{ formatted: '1001 Main St', geo: { lat: '123', lng: '234' } }

在 View 中:

<input type="text" class="form-control" ng-model="item.venue" ng-options="address as address.formatted for address in getLocation($viewValue)" placeholder="Enter address" bs-typeahead>
Venue Object: {{ item.venue }}

我原以为上面的方法可行,但它没有将“格式化”指定为标签值——选择后只是空白。做他下面的工作,但它只将格式化的属性分配给模型:

<input type="text" class="form-control" ng-model="item.venue" ng-options="address. address.formatted as address.formatted for address in getLocation($viewValue)" placeholder="Enter address" bs-typeahead>

fiddle :http://jsfiddle.net/cyberwombat/30e63qea/1/

最佳答案

我想你的意思是你希望你的输入是一个选中的obj的label或者obj.label,但是又想维护obj的选中信息。

您可以捕获 $on selected 事件并添加 .label

  $scope.$on('$typeahead.select', function(v,i){
console.log(v,i);
$scope.selected.label = $scope.selected.formatted_address;
});

这是一个 plunker

关于javascript - AngularStrap typeahead ng-options - 与模型不同的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26874562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com