2012-06-18 45 views
1

在我的控制器里面我有用户点击项目后运行的函数,它加载一个商店并创建/填充TabPanel和DataView(它的工作原理)。当用户只点击一个指定项目(if子句)时,我想分割存储并使用2个DataView创建2个面板。我如何传递自定义参数(record.data.name)来存储侦听器,以便我可以检查哪个项目被点击?或者也许有不同的方法来实现我想要的?这里是我的控制器代码:Extjs 4 MVC自定义参数存储负载监听器

init: function() { 
    this.control({ 
     'gallery_menu': { 
      itemclick: this.show_gallery 
     } 
    }); 
}, 
imageStoreLoaded: function(ImageStore, store1, store2) { 


}, 
show_gallery: function(view, record, item, index, e, opts) { 


    Ext.getCmp('hania-viewport').setLoading('Loading data...'); 

    var tabb = Ext.ComponentQuery.query('.gallery_panel'); 

    var ImageStore = Ext.create('Gallery.store.Images'); 

    ImageStore.load({url: 'myphoto/index.php/api/feed/json/' + record.data.uuid}); 

    var gallery_view; 

    if (record.data.name == 'Specified_item1') { 
     var store1 = Ext.create('Gallery.store.Images'); 
     var store2 = Ext.create('Gallery.store.Images'); 

     //THIS WONT WORK - STORE IS NOT LOADED YET; 
     ImageStore.each(function(r) { 
       if (r.data.name.substring(0, 2) == 'PS') { 
        console.log('PS'); 
        store1.add(r.copy()); 
       }else{ 
        console.log('NOT PS'); 
        store2.add(r.copy()); 
       }    
     }); 

     //IF I ADD LISTENER HOW CAN I RETURN/REFERENCE store1, store2 ??? 
     //OR how can i pass record.data.name so i could check which item was clicked? 
     ImageStore.addListener('load',this.imageStoreLoaded, this); 

     var panel1 = Ext.widget('gallery_view', { 
      title: 'xxx', 
      autoScroll: true, 
      store: store1, 
      flex: 1 
     }); 


     var panel2 = Ext.widget('gallery_view', { 
      title: 'yyy', 
      autoScroll: true, 
      store: store2, 
      flex: 2 
     }); 

     gallery_view = Ext.create('Ext.panel.Panel',{ 
      id: record.data.uuid, 
      title: 'abc', 
      layout: {     
       type: 'hbox', 
       pack: 'start', 
       align: 'stretch' 
      }, 
      closable: true, 
      autoScroll: true, 
      items: [panel1, panel2] 
     }); 

    }else{ 

     gallery_view = Ext.widget('gallery_view', { 
      title: record.data.name + ' - Photo Gallery', 
      id: record.data.uuid, 
      closable:true, 
      scrollable:true, 
      autoScroll: true, 
      store: ImageStore 
     }); 
    } 

    if (tabb[0].down('#' + record.data.uuid)) { 
     tabb[0].setActiveTab(record.data.uuid); 
    }else{ 
     tabb[0].add(gallery_view); 
     tabb[0].setActiveTab(gallery_view); 
    }; 

} 
+0

我想我找到了解决办法。我在show_gallery函数中定义了新函数,然后将其传递给存储监听器,以便store1,store2变量可见。 – patryks

回答

0
And the code: 


show_gallery: function(view, record, item, index, e, opts) { 


    Ext.getCmp('hania-viewport').setLoading('Loading data...'); 

    var tabb = Ext.ComponentQuery.query('.gallery_panel'); 

    var ImageStore = Ext.create('Gallery.store.Images'); 

    ImageStore.load({url: 'myphoto/index.php/api/feed/json/' + record.data.uuid}); 

    var gallery_view; 

    if (record.data.name == 'Do kogo jestem podobna?') { 
     var store1 = Ext.create('Gallery.store.Images'); 
     var store2 = Ext.create('Gallery.store.Images'); 

     function doStuff() { 

      console.log(ImageStore); 

      ImageStore.each(function(r) { 
       if (r.data.raw_name.substring(0, 2) == 'PS') { 
        console.log('PS'); 
        store1.add(r.copy()); 
       }else{ 
        console.log('NOT PS'); 
        store2.add(r.copy()); 
       }    
      }); 

      console.log(store1); 
      console.log(store2); 
     } 


     ImageStore.addListener('load',doStuff, this); 

     var view1 = Ext.widget('gallery_view', { 
      title: 'xxx', 
      store: store1, 
      flex: 1 
     }); 

     var panel1 = Ext.create('Ext.panel.Panel',{ 
      title: 'Tata', 
      items: view1, 
      flex: 1 
     }); 

     var view2 = Ext.widget('gallery_view', { 
      //autoScroll: true, 
      store: store2, 
      flex: 1 
     }); 

     var panel2 = Ext.create('Ext.panel.Panel',{ 
      title: 'Mama', 
      items: view2, 
      flex: 1 
     }); 

     gallery_view = Ext.create('Ext.panel.Panel',{ 
      id: record.data.uuid, 
      title: 'Do kogo jestem podobna?', 
      width: 800, 
      bodyStyle: 'padding: 25px;', 
      layout: {     
       type: 'hbox', 
       pack: 'start', 
       align: 'stretch' 
      }, 
      closable: true, 
      autoScroll: true, 
      items: [panel1, panel2] 
     }); 

    }else{ 

     gallery_view = Ext.widget('gallery_view', { 
      title: record.data.name + ' - Photo Gallery', 
      id: record.data.uuid, 
      closable:true, 
      scrollable:true, 
      autoScroll: true, 
      store: ImageStore 
     }); 
    } 

    if (tabb[0].down('#' + record.data.uuid)) { 
     tabb[0].setActiveTab(record.data.uuid); 
    }else{ 
     tabb[0].add(gallery_view); 
     tabb[0].setActiveTab(gallery_view); 
    }; 

}