需要在lwc中更改picklist值来更新表

chhqkbe1  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(285)

有一个帐户列表,可以将信息传递给子组件。需要更改picklist的值(handlechange中的valuetype),帐户列表也会更改,并将更新的信息传递给子组件。现在,在list.js中进行handlechange,除了更新valuetype外,什么也不做。
listcontroller.cls

public with sharing class listController {

@AuraEnabled (cacheable = true)

public static List<Account> getAccList(String valueType){

String key = '%' + valueType + '%';

    if (valueType != null && valueType != ''){
        return [SELECT Id, Name, image__c, (SELECT Name FROM Users), Budget__c, NumberOfEmployees, Type, Description, Industry FROM Account WHERE Type LIKE :key ];
    } else {
        return [SELECT Id, Name, image__c, (SELECT Name FROM Users), Budget__c, NumberOfEmployees, Type, Description, Industry FROM Account];
    }

        }

}

list.html

<template>
    <lightning-card>

        <template if:true={TypePicklistValues.data}>
            <lightning-combobox name="progress"
                                label="Type"
                                value={valueType}
                                placeholder="-Select-"
                                options={TypePicklistValues.data.values}
                                onchange={handleChange} >
            </lightning-combobox>
      </template><br/>

        <template if:true={accounts.data}>

    <div class = "container">
        <div class="slds-box slds-p-around_none slds-m-top_x-small slds-m-bottom_medium slds-m-horizontal_none">
        <lightning-layout multiple-rows> 

        <template for:each={accounts.data} for:item="account">

                <c-tile 
                key={account.id} 
                account={account} 
                ontileclick={handleTileClick}>
            </c-tile>

        </template>

    </lightning-layout>
</div>
    </div>   
</template>

</lightning-card>

</template>

list.js

import { LightningElement, wire, api, track } from 'lwc';
import getAccList from '@salesforce/apex/listController.getAccList';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import Type_FIELD from '@salesforce/schema/Account.Type';

import getValueType from '@salesforce/apex/listController.getValueType';

export default class List extends LightningElement {

    @wire(getAccList) accounts;
    @wire(getValueType) apexValueType;

    @api valueType;
    @track apexValueType;

    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    objectInfo;

    @wire(getPicklistValues, { recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName: Type_FIELD})
    TypePicklistValues;

    handleChange(event) {
        this.valueType = event.detail.value;
       getAccList({valueType:this.valueType});

    }

    handleTileClick(evt) {

        // This component wants to emit a productselected event to its parent
        const event = new CustomEvent('accountselected', {
            detail: evt.detail,

        });
        // Fire the event from c-list
        this.dispatchEvent(event);
    }
}
31moq8wy

31moq8wy1#

似乎您希望从getacclist方法中访问帐户记录,并将valuetype作为筛选器。
当您在handlechange中对getacclist执行命令式调用时,它不会自动更新属性值,因为它应该返回一个承诺。
要解决此问题,解决方案如下:
或者使用then catch来处理响应,使用neet来分配给class属性。

将参数化导线用作

@wire(getAccList, { valueType: '$valueType'}) accounts;

更改valuetype值时,这将根据值类型自动为帐户记录提供服务

相关问题