将项目插入附加到网格的不可变列表不起作用

Inserting Item to Immutable List Attached to Grid Not working

我正在尝试将虚拟值插入到附加到 Grid.But 的不可变列表中,但在我检查时没有显示任何内容

private filterdSchoolSelectionData: Immutable.List<SchoolSelectionListData> = Immutable.List([]);
   let emptydata: SchoolSelectionListData = {
                    schoolIdentifier: null,
                    schoolName: null,
                    countryID: 1234,
                    countryName: 'asfasf',
                    regionID: null,
                    regionName: null,
                    schoolID: null,
                    isSchoolSelected: true,
                    isCountrySelected: true,
                    isRemoved: false,
                    rowVersion: null
            };
            this.filterdSchoolSelectionData.splice(2, 0, emptydata);
            this.reRender();

列表的大小为 0。

immutablejs 的主要特点是不变性。一个特定的对象引用可能永远不会改变它的数据。这就是为什么所有函数 return 一个带有结果的新集合。

因此您需要将对 splice 的调用输出分配给某些东西,例如this.filterdSchoolSelectionData = this.filterdSchoolSelectionData.splice(2, 0, emptydata);

由于这通常是人们进入 immutable.js 的第一个陷阱,我建议您在开始讨厌自己或图书馆之前先阅读 docs(或至少介绍);- )

PS:reRender 看起来很可疑。在不知道代码细节的情况下,如果您需要手动触发组件的重新渲染,那您就错了。例如。不使用 propsstate 作为您的数据。 List 构造函数的 [] 是不必要的。