我在 initComponent
完成并且表单处于事件状态后调用 init
函数。
为了测试我将其设置如下:
console.log(this.store);
console.log(this.store.getAt(0));
第一个显示商店 - 并且商店有数据。 第二个返回未定义。
为什么会这样呢?如果第一个 console.log
显示数据 - 它也应该已经可用于第二个。
init: function() {
var rec = this.store.getAt(0);
this.setValues(rec);
this.id = rec.id;
}
最佳答案
只需等待商店上的加载事件,然后再访问其数据。我猜控制台相当智能,当对象发生变化时更新内容。
init: function(){
this.store.on('load', function(){
var rec = this.store.getAt(0);
this.setValues(rec);
this.id = rec.id;
}, this);
}
关于javascript - store.getat 未定义 - 但商店已加载并有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26844827/