私は複数のドロップダウン選択を行っていますが、リスト項目を個別に選択することもできます。これは選択要素ではなく、角度成分のデータを保持するtrです。ng-repeatを使って一致する要素にアクティブなクラスを追加する方法
ctrl.checkEquality内のコントローラ内でangular.equalsを使用して、現在の行と、ng-modelを介して渡された値が同じであるかどうかを確認しています。私は基本的に私が持っているコードと似たようなことをすることができますが、 "ctrl"キーが押されたときにmulitで選択された値の配列にそのアクティブなクラスを適用するようにng-modelを設定しますか?
<tr ng-repeat="row in ctrl.filteredItems" ng-class="{'active': ctrl.checkEquality(row, ctrl.ngModel) ng-mousedown="ctrl.onSelectedLocal(row, $event)">
</tr>
public onSelectedLocal(row: ng.IAugmentedJQuery, $event: ng.IAngularEvent) {
if ($event["ctrlKey"]) {
this.setFocusedRow(-1);
this.filterText = "";
// if (this.selectedItems.indexOf(row) === -1) {
// this.selectedItems.push(row);
// for (var i = 0; i < this.filteredItems.length; i++) {
// if (this.filteredItems[i] === row) {
// }
// }
// }
if (this.ngChange) {
this.ngChange({ itemSelected: row });
}
console.log(this.selectedItems);
//we need to make sure the click event of selecting an item in the dropdown stops here
//otherwise it will run into the resetInput function below and not show the selected city in the input element when filterText is used
$event.preventDefault();
$event.stopPropagation();
} else {
this.setFocusedRow(-1);
this.filterText = "";
this.ngModel = row;
this.ngModelValue = (this.showSelectedItem === false) ? "" : row[this.itemDisplayProperty];
if (this.ngChange) {
this.ngChange({ itemSelected: row });
}
this.filteredItems = this.items; //reset filteredItems back to initial items
this.closeDropdown();
//we need to make sure the click event of selecting an item in the dropdown stops here
//otherwise it will run into the resetInput function below and not show the selected city in the input element when filterText is used
$event.preventDefault();
$event.stopPropagation();
}
は、私が「アクティブ」クラスNG-クラスで現在やっているように、任意の一致する行の「アクティブ」クラス(または何を)設定する必要がありますが、ユーザーは、Ctrlキーを押しながらキーを保持している場合、I ctrlが押されている限り、そのアクティブなクラスをすべてのtrに追加できる必要があります。
この時点では、ng-modelは配列ではなく、現在、ユーザーが1つの要素を選択したことに基づいて1つの値しか保持しません。
どうすればいいですか?どんな助けも大歓迎です。
これは単なるコピー&ペーストエラーです。それが問題ではありません。 – bschmitty