【问题标题】:Doesn't update selectedItem in custom dropdown不更新自定义下拉列表中的 selectedItem
【发布时间】:2020-06-03 11:42:28
【问题描述】:

假设有这个下拉菜单:

 <p-dropdown [options]="list" [(ngModel)]="code">
                    <ng-template let-item pTemplate="selectedItem">
                        {{ item.value }} - {{ item.label }}
                    </ng-template>
                    <ng-template let-item pTemplate="item">
                        {{ item.value }} - {{ item.label }}
                    </ng-template>
                </p-dropdown>

在我的 ts 我有:

//loadValue in an object that I have just loaded with this attribute({label, value]}
//list is a list with current dropdown list and it is in this way ({label,vale}]
let index= this.list.findIndex(x => x['value'] === this.loadValue['value']);
        this.code= this.list[index];

问题是 list,loadValueindex 计算正确,但 selectedItem 值没有更新,因为它显示了列表的第一个值,但结果不正确。

【问题讨论】:

  • 你在ts文件哪里使用selectedItem?

标签: angular primeng primeng-dropdowns


【解决方案1】:

您将项目分配给您的 ngModel 而不是值。 您需要传递值。这显然是一个问题,但是如果您认为分配后它没有得到更新,您需要调试实际行为。

this.code= this.list[index].value;

【讨论】:

    猜你喜欢
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2015-12-09
    • 2016-09-16
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多