Ram*_*h S 5 javascript bootstrap-multiselect angular angular6
这个问题可能会被问到,但这并不能解决我的问题multi-select。
在我的angular项目中drop-down,密钥包含database,desktop和account。基于drop-down键的值multi-selectordrop-down和inputbox将被更改。
https://stackblitz.com/edit/angular-ivy-kioexw
我的问题:当我点击第一列作为
database它显示multi-select,但在相同的第1行,如果我选择desktop是databasemulti-select不墙根。请检查下图。
app.component.ts
import { Component, VERSION } from '@angular/core';
declare var $: any;
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
rowArray: Array<any> = [];
newRowArray: any = {};
dbValue = ["mysql", "oracle", "mongo"];
desktopValue = [
{ id: "1", name: "dell" },
{ id: "2", name: "lenovo" },
{ id: "3", name: "hp" }
];
ngOnInit(): void {
this.newRowArray = {
title1: "",
title2: "",
dropdownDataDb: [],
dropdownDataDesktop: [],
isDropDown: true
};
this.rowArray.push(this.newRowArray);
console.log( $('.multiple-select').multiselect())
}
addRow(index) {
this.newRowArray = {
title1: "",
title2: "",
dropdownDataDb: [],
dropdownDataDesktop: [],
isDropDown: true,
isText: false
};
this.rowArray.push(this.newRowArray);
console.log(this.rowArray);
return true;
}
deleteRow(index) {
if (this.rowArray.length == 1) {
return false;
} else {
this.rowArray.splice(index, 1);
return true;
}
}
//multiselect code
multiSelectJquery(){
setTimeout(()=>{
$('.multiple-select').multiselect({
includeSelectAllOption: false,
enableFiltering: true,
includeFilterClearBtn: false,
enableCaseInsensitiveFiltering: true
});
},1);
}
//multiselect code
changed(value: any, index: any) {
this.multiSelectJquery();
if (value == 1) {
this.rowArray[index].isDropDown = true;
this.rowArray[index].isText = false;
this.rowArray[index].dropdownDataDb = this.dbValue;
}
if (value == 2) {
this.rowArray[index].isDropDown = true;
this.rowArray[index].isText = false;
this.rowArray[index].dropdownDataDesktop = this.desktopValue;
}
if (value == 3) {
this.rowArray[index].isDropDown = false;
this.rowArray[index].isText = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序组件.html
<div class="container" style="margin-top: 5%">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>key</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let dynamic of rowArray; let i = index;">
<td (click)="deleteRow(i)">
<i class="fa fa-trash fa-2x"></i>
</td>
<td>
<select [(ngModel)]="rowArray[i].title1" class="form-control" #sel (change)="changed(sel.value, i)">
<option [value]='1'>Database</option>
<option [value]='2'>Desktop</option>
<option [value]='3'>Account</option>
</select>
</td>
<td>
<!-- show db data -->
<select *ngIf="rowArray[i].title1 == 1 && dynamic?.isDropDown" [(ngModel)]="rowArray[i].title2" class="form-control multiple-select" multiple="multiple">
<option *ngFor="let data of rowArray[i].dropdownDataDb;">{{data}}</option>
</select>
<!-- show desktop data -->
<select *ngIf="rowArray[i].title1 == 2 && dynamic?.isDropDown" [(ngModel)]="rowArray[i].title2" class="form-control">
<option *ngFor="let data of rowArray[i].dropdownDataDesktop;">{{data?.name ? data?.name : data}}</option>
</select>
<!-- show account data -->
<input *ngIf="rowArray[i].title1 == 3 && dynamic?.isText" type="text" [(ngModel)]="rowArray[i].title2" class="form-control">
</td>
</tr>
<tr>
<td (click)="addRow(0)">
<i class="fa fa-plus fa-2x"></i>
</td>
</tr>
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题。提前致谢。
小智 2
您可以将代码替换<!-- show db data --><select *ngIf="rowArray[i].title1 == 1 && dynamic?.isDropDown" [(ngModel)]="rowArray[i].title2" class="form-control multiple-select" multiple="multiple"> <option *ngFor="let data of rowArray[i].dropdownDataDb;">{{data}}</option> </select>为:
<!-- show db data -->
<span *ngIf="rowArray[i].title1 == 1 && dynamic?.isDropDown">
<select [(ngModel)]="rowArray[i].title2" class="form-control multiple-select" multiple>
<option *ngFor="let data of rowArray[i].dropdownDataDb;">{{data}}</option>
</select>
</span>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
128 次 |
| 最近记录: |