首页 > 解决方案 > Extjs 存储 getById 返回 null

问题描述

我有一个设备网格面板,我试图为设备提供一个底值,该底值包含在另一个名为 LatestPosition 的商店中。我在网格中添加了“地板”列,现在我想用其他商店的值填充该列。Devices store中的positionId对应LatestPosition store的id,因此可以用来查找设备对应的位置。问题是,当我尝试使用设备的 positionId(使用store.getById)获取最新位置存储中的位置时,我将 null 作为返回值,即使该值似乎存在(下面的屏幕截图):

在此处输入图像描述

所以我需要的值不是空的,但不知何故我无法访问它。

这是我的代码:

updateDevices:function(){          

     Ext.getStore('Devices').each(function (device) {
        var positionId = device.get('positionId');

        console.log(Ext.getStore('LatestPositions').getData().items);

       Ext.getStore('LatestPositions').on('load', function() {
          position = Ext.getStore('LatestPositions').getById('positionId');
        });

        //position is always null!

        if (position) {
            console.log(position.get('attributes').floor);
            floor =  position.get('attributes').floor;
        } else {
            floor =  0;
        }

        device.set({
           "floor": floor
        });
    });
},

标签: extjsstore

解决方案


getById参数应该positionId代替字符串“positionId”。

updateDevices:function(){          

     Ext.getStore('Devices').each(function (device) {
        var positionId = device.get('positionId');

        console.log(Ext.getStore('LatestPositions').getData().items);

       Ext.getStore('LatestPositions').on('load', function() {
          position = Ext.getStore('LatestPositions').getById(positionId);
        });

        //position is always null!

        if (position) {
            console.log(position.get('attributes').floor);
            floor =  position.get('attributes').floor;
        } else {
            floor =  0;
        }

        device.set({
           "floor": floor
        });
    });
},

推荐阅读