为了账号安全,请及时绑定邮箱和手机立即绑定

根据ngfor动态列表中的点击更改文本状态

根据ngfor动态列表中的点击更改文本状态

SMILET 2021-05-03 17:45:45
我已经使用angular 7设置了我的项目。ngFor中有数据列表。我有所有状态文本为待定的产品列表。如果单击批准或拒绝按钮,它将更改列表中的所有文本。对于我点击过的一切。我想做的是,如果我单击列表按钮之一,我想将状态文本从待定更改为“已批准”或“已拒绝”我尝试获取索引值并使用它,但是只有在将其设置为“待批准”时,它才有效。也许我的想法是错误的!setStatus(product: any, index, status){  if (product) {      if(this.indexToAppendClassTo.indexOf(index) === -1)        this.indexToAppendClassTo.push(index);    }   if(status === 'approved'){    this.approved.push(product)  }else {    this.declined.push(product)  }}该indexToAppendClassTo.includes(i)会给你一个布尔值。这是一些代码https://stackblitz.com/edit/angular-y1hsbn?file=src%2Fapp%2Fapp.component.ts我希望能够使产品处于待处理状态,当我单击“批准”或“拒绝”时,它会根据单击将“待批准”的值更改为“批准”或“已拒绝”。这样做有更好的办法吗?
查看完整描述

2 回答

?
莫回无

TA贡献1865条经验 获得超7个赞

所以我从您的代码中知道的是,您总共有三个列表。


您用于迭代(ngFor)的一个,其他两个已批准,如果我错了,请拒绝纠正我。


一种方法是将一个对象与您的产品一起使用,并将另一个键用作状态并根据按钮的单击更改值。


或者


将这些行添加到您的代码中:


  if(status === 'approved'){

    //this line will remove the product from declined list

    this.declined = this.declined.filter(function(value, index, arr){


    return value!== product;


});

    this.approved.push(product)

  }else {

  //this line will remove the product from approved list

  this.approved= this.approved.filter(function(value, index, arr){


    return value!== product;


});

    this.declined.push(product)

  }

}

注意:请确保您从正确的列表中显示结果。


查看完整回答
反对 回复 2021-05-13
  • 2 回答
  • 0 关注
  • 123 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信