【问题标题】:cannot read properties of null (reading 'insertAdjacentHTML') while updating the store更新商店时无法读取 null 的属性(读取“insertAdjacentHTML”)
【发布时间】:2022-06-14 06:11:52
【问题描述】:

更新商店时无法读取 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 的支持。

【问题讨论】:

    标签: javascript html extjs


    【解决方案1】:

    代码可以这样简化:

    if (selectedDRecord.id != undefined || selectedDRecord.id != null) {
       const groupkey = sessionStorage.getItem('groupKey'),
             rowExpanderGridData = Ext.ComponentQuery.query('#' + groupkey)[0].getStore(),
             data = rowExpanderGridData.getData().getRange();
       
       Ext.each(data, 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() 将它们加载到存储中。

    【讨论】:

    • 你甚至可以试试if(!Ext.isEmpty(selectedDRecord.id))。只需使用Ext.each(rowExpanderGridData ),它将遍历商店。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 2022-01-12
    • 2021-12-04
    • 2022-01-06
    相关资源
    最近更新 更多