extjs - 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
});
});
},
解决方案
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
});
});
},
推荐阅读
- haskell - 在这个 hsc2hs 的 #let 构造中重复参数的目的是什么?
- node.js - 开玩笑 - 用“模拟”前缀模拟不起作用
- json - 是否有基于 WebSocket 的标准 PubSub 协议?
- json - 评估序言中的字符串术语
- jenkins - 尝试在同一台服务器上连接 Jenkins 和 Azure DevOps 时出错
- python - JSONDecodeError 期望值:第 1 行第 1 列 (char 0) 与空数组响应
- javascript - 具有某些条件的数字范围的正则表达式
- mysql - 错误代码:1265。列的数据被截断
- python - 我如何运行长度编码模式而不是字符?
- spring-kafka - 如何部署处于暂停模式的 kafka 消费者,直到我发出开始使用消息的信号