更新存储时无法读取null的属性(读取“insertAdjacentHTML”)

vdzxcuhz  于 2022-09-26  发布在  其他
关注(0)|答案(1)|浏览(511)

更新存储时无法读取null的属性(读取“insertAdjacentHTML”)。
我正在尝试通过更改一些数据手动更新我的店铺。
这是我的代码。

updateFieldData: function (selectedDRecord) {
        if (selectedDRecord.id != undefined || selectedDRecord.id != null) {
            let _this = this;
            let groupkey = sessionStorage.getItem('groupKey');
            var rowExapnaderGridData = Ext.ComponentQuery.query('#' + groupkey)[0].getStore();    // this is my gridstore
            var tempStore = [];
            var salesRowData = rowExapnaderGridData.getData().items;
            for (var i = 0; i < salesRowData.length; i++) {
                tempStore.push(salesRowData[i].data);
            }
            for (var i = 0; i < tempStore.length; i++) {
               tempStore[i].value = "somevalue";
            }
            rowExapnaderGridData.loadData(tempStore);
        }

    },

这在创建时工作正常,但当我更新时,我得到以下错误。

Uncaught TypeError: Cannot read properties of null (reading 'insertAdjacentHTML')
    at ctor.insertHtml (ext-all.js?_dc=1654269040829:20:911890)
    at ctor.doInsert (ext-all.js?_dc=1654269040829:20:481469)
    at ctor.append (ext-all.js?_dc=1654269040829:20:481393)
    at ctor.refresh (ext-all.js?_dc=1654269040829:20:1600777)
    at ctor.refresh (ext-all.js?_dc=1654269040829:20:1619324)
    at ctor.refresh (ext-all.js?_dc=1654269040829:20:1862004)
    at ctor.refreshView (ext-all.js?_dc=1654269040829:20:1609433)
    at ctor.onDataRefresh (ext-all.js?_dc=1654269040829:20:1609149)
    at ctor.onDataRefresh (ext-all.js?_dc=1654269040829:20:1870226)
    at ctor.fire (ext-all.js?_dc=1654269040829:20:153709)

我已经在其他地方检查过,但没有得到w.r.t.ExtJS的太多支持。

vcirk6k6

vcirk6k61#

代码可以简化如下:

if (!Ext.isEmpty(selectedDRecord.id)) {
   const groupkey = sessionStorage.getItem('groupKey'),
         rowExpanderGridData = Ext.ComponentQuery.query('#' + groupkey)[0].getStore();

   Ext.each(rowExpanderGridData, function(record) {
       record.set('fieldname', 'some value'); //'fieldname' is the field that you want to change; 'some value' the new value for it
   });

   rowExpanderGridData.commitChanges();
}

或者,您可以创建一个新的模型数组,并使用loadRecords()将其加载到存储区中。

相关问题