2012-04-21 41 views
0

我是新手Sencha用戶。我會編寫一個tab面板,並在每張表格中放入一個表格。 我嘗試定義MainForm的變種,並把2標籤,但如果我點擊2選項卡上的按鈕,我已經回到一個空白麪板....Sencha-touch 2 - 在標籤面板內形成

我做錯了嗎? 謝謝。

//<debug> 
Ext.Loader.setPath({ 
    'Ext': '../../src' 
}); 
//</debug> 

/** 
* This is a simple example that demonstrates the Ext.TabPanel component. 
* 
* It will simply create a Ext.tab.Panel component with three children and add it to the viewport. 
*/ 
Ext.application({ 
    glossOnIcon: false, 
    icon: { 
     57: 'resources/icons/icon.png', 
     72: 'resources/icons/[email protected]', 
     114: 'resources/icons/[email protected]', 
     144: 'resources/icons/[email protected]' 
    }, 

    phoneStartupScreen: 'resources/loading/Homescreen.jpg', 
    tabletStartupScreen: 'resources/loading/Homescreen~ipad.jpg', 

    //next we require any components we are using in our application. 
    requires: [ 
     'Ext.tab.Panel', 
     'Ext.form.*', 
     'Ext.field.*', 
     'Ext.Button', 

     'Ext.data.Store' 
    ], 

    /** 
    * The launch function is called when the browser and the framework is ready 
    * for the application to launch. 
    * 
    * All we are going to do is create a simple tabpanel with 3 items, and add 
    * it to the global Ext.Viewport instance. 
    */ 
    launch: function() { 
     //we send a config block into the Ext.Viewport.add method which will 
     //create our tabpanel 
     var mainForm = Ext.create('Ext.form.Panel', { 
      fullscreen: true, 
      items: [ 
       { 
        xtype: 'textfield', 
        name : 'name', 
        label: 'Name' 
       }, 
       { 
        xtype: 'emailfield', 
        name : 'email', 
        label: 'Email' 
       }, 
       { 
        xtype: 'passwordfield', 
        name : 'password', 
        label: 'Password' 
       } 
      ] 
     }); 


     Ext.Viewport.add({ 
      //first we define the xtype, which is tabpanel for the Tab Panel component 
      xtype: 'tabpanel', 

      //next we define the items that will appear inside our tab panel 
      items: [ 
       { 
        //each item in a tabpanel requires the title configuration. this is displayed 
        //on the tab for this item 
        title: '1-tab', 

        //next we give it some simple html 
        items: { 
         html: '1', 
         centered: true 
        }, 

        //then a custom cls so we can style it 
        cls: 'card1' 
       }, 
       { 
        //title 
        title: '2-tab', 

        //the items html 
        items: [mainForm], 

        //custom cls 
        cls: 'card2' 
       }, 
       { 
        //title 
        title: '3-tabs', 

        //the items html 
        items: { 
         html: '3', 
         centered: true 
        }, 

        //custom cls 
        cls: 'card3' 
       } 
      ] 
     }); 
    } 
}); 

回答

2

你做得不對。

您正在將mainForm嵌套在items[]陣列中。它不應該是這樣。

而是分別創建每個項目並添加到TabPanel的項目數組中。

演示: -

Ext.Loader.setConfig({ 
    enabled: true 
}); 

Ext.application({ 
    name: 'SenchaFiddle', 

    launch: function() { 
     var mainForm = Ext.create('Ext.form.Panel', { 
      fullscreen: true, 
      title:'2-tab', 
      items: [ 
       { 
        xtype: 'textfield', 
        name : 'name', 
        label: 'Name' 
       }, 
       { 
        xtype: 'emailfield', 
        name : 'email', 
        label: 'Email' 
       }, 
       { 
        xtype: 'passwordfield', 
        name : 'password', 
        label: 'Password' 
       } 
      ] 
     }); 

     var htmlForm1 = Ext.create('Ext.form.Panel',{ 
       title: '1-tab', 

       //next we give it some simple html 
       items: { 
       html: '1', 
       centered: true 
       }, 

       //then a custom cls so we can style it 
       cls: 'card1' 
     }); 

     var htmlForm3 = Ext.create('Ext.form.Panel',{ 
      title: '3-tab', 

       //next we give it some simple html 
      items: { 
       html: '3', 
       centered: true 
      }, 

      //then a custom cls so we can style it 
      cls: 'card3' 
     }); 

     Ext.Viewport.add({ 
      //first we define the xtype, which is tabpanel for the Tab Panel component 
      xtype: 'tabpanel', 

      //next we define the items that will appear inside our tab panel 
      items: [htmlForm1,mainForm,htmlForm3] 
     }); 
    } 
}); 

輸出: enter image description here