问题 角材料设计

问题描述 投票:2回答:1

我的问题是:我有垫芯片列表,如果我关闭第一个项目它没关系,如果我关闭最后一个项目都关闭:

enter image description here

这是我的HTML:

<mat-form-field>
  <mat-chip-list #chipList>
    <mat-chip *ngFor="let keyword of keywords" [removable]="removable" (removed)="remove(keyword)">
      {{ keyword }}
      <mat-icon matChipRemove>cancel</mat-icon>
    </mat-chip>
    <input placeholder="{{ 'consultantSearchPage.searchForConsultantOrSkills' | translate }}" [matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
      (matChipInputTokenEnd)="addSearch($event)">
  </mat-chip-list>
</mat-form-field>

这是我的意思:

remove(keyword): void {
  const index = this.keywords.indexOf(keyword);
  if (index >= 0) {
    this._store.dispatch({ type: UPDATE_KEYWORDS, payload: index});
  }
}

如果我使用:

remove(keyword): void {
  const index = this.keywords.indexOf(keyword);
  if (index >= 0) {
    this.keywords.splice(index, 1);
  }
}

没关系,但我的数据没有更新

这是我的减速机代码:

export const UPDATE_KEYWORDS = 'UPDATE_KEYWORDS';
.......
case UPDATE_KEYWORDS:
  console.log( state.keywords.splice(0, 1));
  return Object.assign({}, state, { keywords: state.keywords.splice(action.payload, 1) });
javascript typescript angular-material
1个回答
0
投票

从你的评论你这样做:

case UPDATE_KEYWORDS:
  console.log( state.keywords.splice(0, 1));
  return Object.assign({}, state, { keywords: state.keywords.splice(action.payload, 1) });

你应该这样做:

case UPDATE_KEYWORDS:
  state.keywords.splice(action.payload, 1);
  console.log(state.keywords);
  return Object.assign({}, state, { keywords: state.keywords });

您希望使用已拼接的数组,而不是拼接返回的数组。

https://www.w3schools.com/jsref/jsref_splice.asp

© www.soinside.com 2019 - 2024. All rights reserved.