Extjs存储getById返回null
我有一个设备网格面板,我试图给这些设备一个下限值,它包含在另一个名为LatestPosition的商店中。我在网格中添加了“floor”列,现在我想用其他商店的值填充该列。Devices store中的positionId与LatestPosition store的id相对应,因此可以使用它查找设备的相应位置。问题是,当我尝试使用设备的positionId(使用Extjs存储getById返回null,extjs,store,Extjs,Store,我有一个设备网格面板,我试图给这些设备一个下限值,它包含在另一个名为LatestPosition的商店中。我在网格中添加了“floor”列,现在我想用其他商店的值填充该列。Devices store中的positionId与LatestPosition store的id相对应,因此可以使用它查找设备的相应位置。问题是,当我尝试使用设备的positionId(使用store.getById)获取LatestPosition存储中的位置时,返回值为null,即使该值似乎存在(下面的屏幕截图): 所
store.getById
)获取LatestPosition存储中的位置时,返回值为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')。每个(函数(设备){
var positionId=device.get('positionId');
log(Ext.getStore('LatestPositions').getData().items);
Ext.getStore('LatestPositions')。on('load',function(){
position=Ext.getStore('LatestPositions').getById(positionId);
});
//位置总是空的!
如果(职位){
console.log(position.get('attributes').floor);
地板=位置。获取('attributes')。地板;
}否则{
地板=0;
}
设备集({
“地板”:地板
});
});
},
也许,您应该创建一个sencha fiddle示例。您显示的记录的id是什么?我想您需要相应地将模型的idProperty设置为您的positionId。更多信息请点击此处: