刷新或更新行,并在Angular4中单击相应的按钮

时间:2018-02-24 19:03:27

标签: angular typescript

我有这段代码将 json 的详细信息呈现给我的组件:

<tr *ngFor="let wall of userWall">
    <td *ngFor="let item of keys" [hidden]="!item.visible" [ngStyle]="{'text-align':'left'}">
        <span *ngIf="item.fieldName=='walladdress' && wall[ item.fieldName]!=''">{{ wall[item.fieldName] }}</span>
        <span *ngIf="item.fieldName=='walladdress' && wall[ item.fieldName]==''">
            <button type="submit" class="btn btn-primary" (click)="GenerateWall(wall.currid)">Generate</button>
        </span>
        <span *ngIf="item.fieldName!='walladdress'">{{ wall[item.fieldName] }}</span>
    </td>
</tr>

现在点击按钮,我正在创建一个墙并将其发送回前端。但我对如何将新生成的墙放置到相应的行单元格有点困惑。在创建墙之后,我似乎无法刷新数据。这是我称之为的函数:

GenerateWallet(currid){
    this.UserApi.GenerateWall(currid).subscribe(data => {
        getUserWall();
    })
}

getUserWall(){
    this.UserApi.GetUserWall().subscribe(data => {
        if (Array.isArray(data)) {
            this.userWall = data;
        }
    })
}

filteredCurrencies
  init() {
    var wall = this.userWall
    this.filteredCurrencies = []
    for (var currencyIndex in this.currencies) {
      var flag = true
      var currency = this.currencies[currencyIndex]
      for (var index in wall) {
        var wall = wall[index]
        if (wall.currid == currency.currid) {
          flag = false
          break;
        }
      }
      if (flag) {
        this.filteredCurrencies.push(currency)
      }
    }
  }

绑定的json数据是这样的:

[
  {
    "currid": 1,
    "currencyname": "XXXX",
    "currencyshortname": "XXX",
    "cursymbolurl": "xxxx",
    "walletacid": 1719,
    "accountid": 1044,
    "fundslocked": 0.0,
    "walladdress": "ffaab3be-1958-11e8-886a-8512c9ba4a42",
    "bal": "",
    "usdvalue": "",
    "availabal": ""
  },
  ...
]

我没有Angular4的背景,甚至没有AngularJS。其中一个UI留在中间,我只需要完成它。只需了解模式并巧妙地重用已经创建的代码。

0 个答案:

没有答案