How to Embed a NestedList in a TabPanel?

吃可爱长大的小学妹 提交于 2019-12-01 18:50:44

Okay. I have created this example for you: http://www.senchafiddle.com/#ynn40

You can also download the whole source from here: http://rwd.me/FG5s (quite large as it includes the SDK)

Be sure to look through all the files as I have added lots of documentation.

Some notes:

  1. I created a new component called Sencha.view.SplitView. This obviously can be called anything. It has a xtype of splitview so we can simply just require it and include it into our Main.js file (which is a Ext.tab.Panel.

    {
        xtype: 'splitview',
        title: 'SplitView',
        store: 'Items'
    }
    

    Because this is an item inside a tabPanel, we need to give it the title configuration too. Of course we could include this Splitview component anywhere.

  2. As you can see it has a store configuration which is defined in SplitView:

    config: {
        /**
         * We create a custom config called store here so we can pass the store from this component
         * (SplitView) down into the nested list when it updates. Checkout {@link #updateStore}
         * @type {Ext.data.Store}
         */
        store: null
    }
    

    This is used to pass the store from the splitview to the nested list (we will get to that in a second). Of course that configuration will do nothing unless we add the appropriate methods to update the nested list:

    /**
     * This is called when the {@link #store} config has been updated.
     * We simply check if the nested list has been created, and if it has, set the store
     * on it with the new value.
     */
    updateStore: function(newStore) {
        if (this.nestedList) {
            this.nestedList.setStore(newStore);
        }
    }
    

    As you can see, we are simply updating the nestedList (if it exists) store with the new value of the SplitView store.

  3. Inside the initialize method of SplitView, we created both the detailContainer (where the detail card of the nested list should go) and the nestedList and then add them to the SplitView. Make sure you look at some of the configurations that we give nestedList as they are important. The store configuration:

    // Set the store of this nested list to the store config of this component (Splitview)
    store: this.getStore()
    

    The detailCard and detailContainer configurations:

    // Tell the nested list to have a detail card and put it inside our new detailContinaer
    detailCard: true,
    detailContainer: this.detailContainer
    

    And of course the listeners so we know when things get changed:

    // And finally add a listener so we know when to update the detail card
    listeners: {
        scope: this,
        leafitemtap: this.onLeafItemTap
    }
    
  4. Finally we add the onLeadItemTap method into the Splitview (we added the listener above) which should update the detail card with new information:

    /**
     * This is called when a leaf item is tapped in the nested list, or when the detail card
     * should be updated. In here, we just get the record which was tapped and then set the HTML
     * of the detail card.
     */
    onLeafItemTap: function(nestedList, list, index, node, record, e) {
        var detailCard = nestedList.getDetailCard();
        detailCard.setHtml(record.get('text'));
    }
    

Hopefully this makes sense and helps you. If not, let me know.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!