lwc select-rows 属性不会更新树网格?

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

我试图在闪电树网格中选择父行时自动选择(复选框)嵌套行。

据我了解,闪电树网格上的 selected-rows 属性可能可以做到这一点。我不知道我所做的是否是错误的,或者我没有给它工作所需的东西。我已经提供了“大部分”代码的屏幕截图来提供帮助。我确实找到了与我的问题相关的其他支持链接,但我仍然无法让它工作。

lwc 与选择行的连线问题

选择父级时自动选择子级

HTML

<div class="spinnerHolder">
        <template if:true={isLoading}>
            <lightning-spinner alternative-text="loading"></lightning-spinner>
        </template>
        <lightning-tree-grid
            lwc:if={treeGridData.length}
            class="results"
            data-id="gridResult"
            columns={gridColumns}
            data={treeGridData}
            key-field="contactName"
            expanded-rows={expandedList}
            selected-rows={selectedData}
            onrowselection={selectRowHandler}
        >
        </lightning-tree-grid>
    </div>

JS

@track selectedData = [];

    selectRowHandler(event) {
        let temp = [];
        for (let i = 0; i < event.detail.selectedRows.length; i++) {
            temp.push(event.detail.selectedRows[i]);
        }
        this.selectedData = temp;
        console.log('selected Data', this.selectedData);
    }


//probably dont need to show ALL of this but..
@wire(getResults, { filterString: '$bindFilters' })
    contactsResult({ error, data }) {
        this.gridisLoading = true;
        this.contactsCount = 0;
        this.offset = 0;
        console.log(data);
        if (data) {
            const rawData = data;
            this.contactsCount = rawData.length;
            if (this.contactsCount === 0) {
                this.gridisLoading = false;
                this.activateSearch();
            } else {
                try {
                    this.initialData = dataHelper.transformDataObject(rawData);
                    this.downloadData = downloader.createCsvContent(rawData);
                    // console.log(this.downloadData);
                    if (this.missingPersons.length > 0) {
                        this.initialData = dataHelper.filterForMissingPerson(this.initialData, this.missingPersons);
                        this.downloadData = downloader.filterForMissingPersonDownload(this.downloadData, this.missingPersons);
                    }

                    this.sliceData();
                } catch (e) {
                    this.handleError(e);
                } finally {
                    this.gridisLoading = false;
                    this.activateSearch();
                }
            }
        } else if (error) {
            this.handleError(error);
        }
        this.gridisLoading = false;
        this.activateSearch();
    }

html

event

dummy example

checkbox attributes salesforce-lightning lwc treegrid
1个回答
0
投票

这最终成为我对@track 与@api 的理解。 @api 公开变量,@track 很好地跟踪更改。然而,每次 $bindfilters 更改时,它也会清除 selectedData,这没有帮助。所以基本上是我的误解的结合。

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