从 LWC 中的数组更改对象字段值

问题描述

我无法在这部分更新数组中的对象字段值。

this.wiredProducts[0].Price__c = this.selectedRate;

我可以得到这个值,但不能用它做任何事情。它抛出这样的错误:

[NoErrorObjectAvailable] 脚本错误。

所以可能有人对这个问题有所了解。 代码如下。

    import { LightningElement,wire,track,api } from 'lwc';  
    import getActiveProducts from '@salesforce/apex/GetActiveProducts.getSearchedProducts';  
    export default class IterationInLwc extends LightningElement {  
      @api searchedName;
      @api searchedPrice;
      wiredProducts;
      rates;
      @api selectedRate = 1;
      @track searchedProducts;
      @track error;
      @wire(getActiveProducts)
      wiredProduct({ error,data }) {
        if (data) {
            console.log(data);
            this.wiredProducts = data.productList;
            this.rates = data.rates;
            
            this.searchedProducts = this.wiredProducts;
            console.log(this.prices);
            
            console.log(this.searchedProducts);
        } else if (error) {
            this.error = error;
        }
     }
    
      handleSearchByName(event){
        this.searchedName = event.target.value;
        this.searchedProducts = this.wiredProducts.filter
        (product => product.Name.includes(this.searchedName) && product.Price__c >= this.searchedPrice);
      }
    
      handleSearchByPrice(event){
        this.searchedPrice = parseFloat(event.target.value);
        this.searchedProducts = this.wiredProducts.filter
        (product => product.Name.includes(this.searchedName) && product.Price__c >= this.searchedPrice);   
      }
      handleMenuSelect(event) {
        this.selectedRate = event.detail.value;
        this.wiredProducts[0].Price__c = this.selectedRate;
    
      }
    }  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)