【发布时间】:2018-06-12 13:56:14
【问题描述】:
我正在使用下拉列表和 select2,我需要编辑产品,当然,所选产品在下拉列表中包含一个所属组/类别,但是当我打开模式时,未选择该组,即使值存在,这是我尝试实现的方法:
1.) 用所有类别填充下拉列表(有效)
(*ngFor="let category of mainGroups)
2.) 根据所选文章选择对应的值(不起作用)
<!--category-->
<div class="form-category">
<label class="control-label dash-control-label col-xs-3">Product category:</label>
<div class="col-xs-9">
<select touch-enter-directive [ref]="ref" [nextFocusElement]="articleSubGroup" id="mainGroupSelectEdit" class="form-control dash-form-control select2" style="width: 100%;"
data-minimum-results-for-search="Infinity" name="mainGroupSelectEdit" required (change)="filterSubById(article.groupId)" [(ngModel)]="article.groupId">
<option disabled>-/-</option>
<option [value]="category.id" *ngFor="let category of mainGroups" [selected]="category.id==='a0e25215-a60e-4444-b6ac-4521b7de4b37'">{{category.title}}</option>
</select>
{{article.mainGroup.id}} <- here is shown value a0e25215-a60e-4444-b6ac-4521b7de4b37, so I thought that value should be selected in dropdown
</div>
</div>
你可以看到我用过的人
[selected]="category.id==='a0e25215-a60e-4444-b6ac-4521b7de4b37'"
因为我认为这可能会像这样工作,但不知不觉它不能......
【问题讨论】:
标签: javascript jquery angular jquery-select2