在一個div中,我填充了所需的複選框。將選中的複選框從一個div移動到另一個div。如果取消選擇其他div,它應該反映在最初的div
此外,我設法將選定的複選框存儲到一個對象。
我想知道如何顯示在另一個DIV這個對象(複選框)。另外,如果我取消選擇其他div,它應該也反映在最初的div(雙向綁定)。 以下代碼用於填充選定的複選框。
selectedUsers(usrbysite: any, event: any) { //getting values of selected check boxes
var index = this.checkeduserslist.indexOf(usrbysite);
if (event.target.checked) {
if (index === -1) {
this.checkeduserslist.push(usrbysite);
console.log('added', usrbysite);
}
}
else {
if (index !== -1) {
this.checkeduserslist.splice(index, 1);
console.log('removed', usrbysite);
}
}
console.log('CHECKEDUSERSLIST :', this.checkeduserslist);
}
下面的代碼是最初填充DIV:
<div style="width:100%; height:120px; overflow-x: auto;">
<div *ngFor="let usersbysite of usersbysite" style="display:inline">
<input type="checkbox"
name="usersbysite"
value="usersbysite.user"
(change)="selectedUsers(usersbysite, $event)" />
{{usersbysite.username}}
</div></div>
我想在另一個div來填充對象命名selecteduserlist 。
更新: 在下面顯示的圖像中,我填充了複選框。當我點擊任何這些複選框時,它應該轉到上面的框中。此外,當我從上面的框中取消選中,它應該從上面的框中刪除,並且其下面的框中的相應值應該是未選中的。
問題是什麼?而且你有什麼確切的想法有點不清楚。你是否想在其他div中使用複選框?你能否解釋一下這個用例,因爲我很難理解這是什麼。 – Alex
@ AJT_82請參閱編輯先生。 –
基本上我想知道選中的複選框是否可以使用ngModel顯示在上面的框中,以便檢查/取消選中事件相互影響。 –