gpt4 book ai didi

javascript - Angular JS ui-select选项重复不适用于对象数组

转载 作者:行者123 更新时间:2023-12-03 03:49:48 24 4
gpt4 key购买 nike

我正在使用 Angular ui-select。我的模型和 ui-select 选项数组不同。更改值时,它不会更新并且不显示选项。我将选定的对象 ID 存储在“pmpo”中,我想在加载时显示 pmptnk 对象数组中选定的对象。但不工作。有人告诉我我做错了什么。

我的模型对象

  pmpo:877
pmptnk:[0:
632:{id: "632", pid: "2993", ESID: "9154", lb1: "Undddd", lb2: "219"}
877:{id: "877", pid: "2993", ESID: "9154", lb1: "Pcddd", lb2: "29"}
654:{id: "654", pid: "2993", ESID: "9154", lb1: "kukuu", lb2: "246"}]

在查看文件

 <div ng-if="item.pmptnk.length > 0">
<ui-select ng-model="item.pmpo" click-out-side="closeThis($event)">
<ui-select-match placeholder="Select " search-placeholder="Filter Tanks"
uib-tooltip="{{item.pmpo > 0 ? $select.selected.lb1 : 'Select Tank'}}" tab-select="true">
<span ng-bind="$select.selected.lb1"></span>
</ui-select-match>
<ui-select-choices repeat="obj.tid as obj in (item.pmptnk[item.pmpo])">
<span ng-bind="obj.lb1"></span>
</ui-select-choices>
<ui-select-no-choice>
No results matched "{{$select.search}}"
</ui-select-no-choice>
</ui-select>

</div>

最佳答案

根据 docs of ui-select-choicesrepeat 属性

Specify the list of items to provide as choices. Syntax is similar to ngRepeat.

根据ng-repeat doc

It is possible to get ngRepeat to iterate over the properties of an object using the following syntax:

<div ng-repeat="(key, value) in myObj"> ... </div>

因此,我们可以得出结论,您应该更改语法:

<ui-select-choices repeat="obj.tid as obj in (item.pmptnk[item.pmpo])">

对此:

<ui-select-choices repeat="(key, value) in (item.pmptnk[item.pmpo])">

其中value将为8772993等,key将为idpid 等等。

关于javascript - Angular JS ui-select选项重复不适用于对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45216180/

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