- 以前想调用某个子组件的,如果不想总是通过Ext.getCmp()方法,就需要写一大串的items去访问,非常麻烦。
示例代码:
- StuEvaluateManageUI = Ext.extend(Ext.Viewport, {
- layout: 'fit',
- initComponent: function () {
- this.items = [
- {
- xtype: 'grid',
- // ref: 'mygrid',
- id: 'StuEvaluateManageGrid',
- store: 'StuEvaluateManageJson',
- viewConfig: {
- forceFit: true
- },
- loadMask: true,
- colModel: new Ext.grid.ColumnModel({
- defaults: {
- width: 2,
- xtype: 'gridcolumn',
- align: 'center',
- sortable: true
- },
- columns: [
- {
- dataIndex: 'Student_name',
- width: 1,
- header: '学生姓名'
- },
- {
- dataIndex: 'Course_name',
- header: '课程名'
- }
- ]
- })
- }
- ];
- StuEvaluateManageUI.superclass.initComponent.call(this);
- }
- });
为了解决这个问题,我先是通过如下代码实现:
- Ext.apply(StuEvaluateManageView, { /*签到grid*/mygrid: Ext.getCmp('StuEvaluateManageGrid'});
然后就可以通过StuEvaluateManageView.mygrid直接就可是调用grid组件。
后来悲催地发现居然有ref这个属性,才发现自己的方法有多笨,泪奔。直接加上上述的注释的 ref: 'mygrid'配置项,即可轻松实现StuEvaluateManageView.mygrid访问的grid的功能了