extjs如何获取网格 [英] extjs How to get a grid
问题描述
点击按钮addRecord被调用,它会失败,其中行被赋值以获取未定义的网格。 p>
如何定义这个MyGrid,以便它引用面板中的网格?
Ext.define('MyApp.view.MyPanel',{
extends:'MyApp.view.ui.MyPanel',
initComponent:function(){
var me = this;
me.callParent(arguments);
var button = me.down('button [text = Submit]');
按钮.on('click',me.onSubmitBtnClick,me);
},
addRecord:function(myRecordArray){
var rows = grid.getStore ).getRange(); //这里发生错误
console.log(rows);
},
onSubmitBtnClick: function(){
this.addRecord([ll,kk,mm]);
}
});
Chrome Javascript调试器控制台 - >
未捕获ReferenceError:没有定义网格
在调用 grid.getStore()
之前,需要定义grid。您可以在调用前直接执行 var grid = this;
,因为您正在从网格内部定义addRecord函数。
编辑:
我刚刚注意到,这个没有从网格面板中与商店调用,但是其他面板。您将要做的是在网格面板上设置一个id配置。例如。 id:MyGridPanel
可能已经有一个id配置设置,你只需要找出它是什么。如果您正在使用ExtJS设计器,那么<em>可能实际上已经设置为MyGridPanel。那么你可以这么称呼:
var grid = Ext.getCmp(MyGridPanel);
然后你会做:
grid.getStore()。getRange()
In Designer I set my grid name to equal MyGrid
On clicking the button addRecord is called, it fails where rows is attemting to get an undefined grid.
How do I define this MyGrid so that it references the grid within the panel?
Ext.define('MyApp.view.MyPanel', {
extend: 'MyApp.view.ui.MyPanel',
initComponent: function() {
var me = this;
me.callParent(arguments);
var button = me.down('button[text=Submit]');
button.on('click', me.onSubmitBtnClick, me);
},
addRecord: function(myRecordArray) {
var rows = grid.getStore().getRange(); // ERROR happens here
console.log(rows);
},
onSubmitBtnClick: function() {
this.addRecord(["ll", "kk", "mm"]);
}
});
Chrome Javascript Debugger Console ->
Uncaught ReferenceError: grid is not defined
Before you call grid.getStore()
you need to define "grid". You can just do var grid = this;
right before the call because you are defining the addRecord function from inside of the grid.
EDIT:
I just noticed that this wasn't being called from inside the grid panel with the store but some other panel. What you will have to do to is set an id config on your grid panel. E.g. id: MyGridPanel
There may already be an id config set on it and you just have to find out what it is. If you are using the ExtJS designer it may actually already be set to "MyGridPanel". Then you would call it like so:
var grid = Ext.getCmp("MyGridPanel");
then you would do:
grid.getStore().getRange()
这篇关于extjs如何获取网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!