Extjs 4.2.1 – config autoLoad:false失败

前端之家收集整理的这篇文章主要介绍了Extjs 4.2.1 – config autoLoad:false失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我定义了一个treepanel扩展扩展:’Ext.tree.Panel’和initComponent函数一样
  1. Ext.define('Example',{
  2. extend: 'Ext.tree.Panel',title: 'Example',useArrows:false,rootVisible: false,border: false,initComponent: function () {
  3. var store = Ext.create('Ext.data.TreeStore',{
  4. fields: [
  5. {name: 'id',type: 'string'},{name: 'text',type: 'string'}
  6. ],autoLoad : false,// not working
  7. proxy: {
  8. type: 'ajax',url: 'data.PHP',reader: {
  9. type: 'json',root: 'results'
  10. }
  11. }
  12.  
  13. });
  14. this.store = store;
  15. this.callParent(arguments);
  16. }
  17. });

我尝试设置autoLoad:false但是当我创建我的treepanel时总是加载

当我尝试配置下面的代码存储然后autoLoad:false工作但加载后我的treepanel是空白

  1. root: {
  2. text: 'Ext JS',id: 'src',expanded: false // this
  3. }

如果不使用root配置,我的json很好并且正常工作

  1. ({ "results": [
  2. {
  3. id : '1',text : '1',expanded: true,results :[{
  4. id : '2',text : '2',leaf:true
  5. }]
  6. },{
  7. id : '3',text : '3',leaf:true
  8. }]
  9. })

如何解决这个问题.

您必须重写Ext.tree.Panel.setRootNode metod以考虑商店的autoLoad属性.

以下示例使用ExtJS v4.2.2进行测试.

  1. Ext.define('Example',/**
  2. * Override.
  3. */
  4. setRootNode: function() {
  5. if (this.getStore().autoLoad) {
  6. this.callParent(arguments);
  7. }
  8. },proxy: {
  9. type: 'ajax',url: '/data.PHP',root: 'results'
  10. }
  11. }
  12.  
  13. });
  14. this.store = store;
  15. this.callParent(arguments);
  16. }
  17. });
  18.  
  19. Ext.onReady(function(){
  20.  
  21. var tree = Ext.create('Example',{
  22. renderTo: Ext.getBody(),width: 300,height: 300
  23. });
  24.  
  25. tree.getStore().load();
  26. });

猜你在找的PHP相关文章