javascript - 在 angularjs ui-select 指令中更新后,如何默认设置搜索字段中的更新值?
问题描述
我在 angularjs ui-select 指令中遇到问题。它工作正常,它在下拉列表中显示了完整的数据。当我从搜索字段中选择一个值并想要更新它时,它会更新,但默认情况下它不能显示在搜索字段中。我必须再次手动搜索才能看到更新的值。让我粘贴代码...
这是angularjs代码
$scope.consignee = [];
$http.get("get-consignee", {
}).then(function(response){
$scope.consignee = response.data;
//$scope.consignee.selected = $scope.consignee[0];
});
这是用户界面选择代码
<ui-select ng-model="consignee.selected" theme="select2">
<ui-select-match placeholder="Select Consignee">
<% $select.selected.CONSIGNEE_NAME %>
</ui-select-match>
<ui-select-choices ng-repeat="e in consignee | filter: $select.search">
<div><% e.CONSIGNEE_NAME %></div>
</ui-select-choices>
</ui-select>
假设我在下拉列表中有 5 个收货人姓名!
1. hamad
2. test2
3. yasin Gul
4. hamid
5. munir
所以问题是,当我使用它时,它会$scope.consignee.selected = $scope.consignee[0];
在0
索引处给出hamad
更新后的名称,即使我进行了更新test2
,或者yasin Gul
它hamad
在搜索字段中默认设置为我。我知道我有0
, 1
, 2
, 3
,4
索引,但我希望它是动态的而不是手动的。我只想设置我更新的那个名字。如果我更新test2
,以便它应该test2
在更新后默认设置在搜索字段中给我,对于yasin Gul
等。任何帮助将不胜感激谢谢
解决方案
cons_id
是您选择的数据库 ID。
$scope.consignee = [];
$http.get("get-consignee", {
}).then(function(response){
$scope.consignee = response.data;
var index = $scope.consignee.findIndex(x => x.CONSIGNEE_ID==cons_id); // use this
$scope.consignee.selected = $scope.consignee[index];
});
推荐阅读
- regex - text - 查找所有没有特定表达式的行
- flutter - 当 SliverAppBar 滚动时,flexibleSpace 内的图标不会隐藏
- integer - 当输入文件既有整数又有文本时,如何在fortran90中正确读取整数?
- r - 有没有办法为按行以编程方式选择的 data.table 列分配值?
- performance - 我应该使用视频或 GIF 在网站上显示多个循环和自动播放视频吗?
- python - 使用for循环的不止一个类别python的ARIMA
- r - 根据第二个数据帧总结一个数据帧
- excel - 如何在同一 if 语句中回收长公式
- django - 创建多个postgres数据库时Docker撰写错误
- probability - 矩形区域的连续概率计算