添加按钮并在视图之间导航

时间:2012-04-27 18:02:55

标签: sencha-touch extjs sencha-touch-2

1。)我需要添加2个按钮,一个在另一个下面。到目前为止,我的工作如下所示;它只显示一个按钮,但如何在此按钮下面添加另一个带有不同按钮图像的按钮?

2。)当用户点击按钮时,我需要导航到另一个屏幕。我怎样才能做到这一点 ? 我需要等效的以下Objective-c代码?

View1 *view1 = [[View1 alloc] initWithNibName:@"View1" bundle:nil];
            [self.navigationController pushViewController:View1 animated:YES];

3.。)如何添加导航栏(相当于iPhone中显示的导航栏)

第一个问题的代码;

{
                items:[
                    {
                        xtype:'button',
                        text: 'Submit',
                        ui:'confirm',
                        handler: function(){
                          var values = Ext.getCmp('contactForm').getValues();

                          Ext.Ajax.request({

                            url: 'http://loonghd.com/service/',

                            failure: function (response) {
 //do something
            },                              success: function (response) {
                                                                         // do something
                            }

                           });
                        }
                    }
                ]

            }

2 个答案:

答案 0 :(得分:1)

也许导航视图适合您?这是相同的想法,但它就像从UITableView开始:

http://docs.sencha.com/touch/2-0/#!/example/navigation-view

在app / controller / Application.js中,当您点击某个联系人时,会推送详细信息视图。所有源都在示例目录中。

    onContactSelect: function(list, index, node, record) {
        var editButton = this.getEditButton();

        if (!this.showContact) {
            this.showContact = Ext.create('AddressBook.view.contact.Show');
        }

        // Bind the record onto the show contact view
        this.showContact.setRecord(record);

        // Push the show contact view into the navigation view
        this.getMain().push(this.showContact);
    },

答案 1 :(得分:1)

1)为了让两个按钮一个在另一个下面,您可以添加两个单独的按钮(具有不同的ui属性)作为表单面板的子项。我想,这就是你需要的。

就像这样,

   ....
   ....
   items : [
       {
         xtype:'button',
         text: 'Submit',
         ui:'confirm', // makes the button color as green
         handler: function(){
            var values = Ext.getCmp('contactForm').getValues();
            Ext.Ajax.request({
                 url: 'http://loonghd.com/service/',
                 failure: function (response) {
                        //do something
                  },

                 success: function (response) {
                         // do something
                 }
            });
           }
          },
          {
              xtype:'button',
              text:'Second button',
              ui:'decline', // makes the button color as red.
              listeners : {
                  tap : function() {
                     Ext.Msg.alert('You just clicked Second button');
                  }
               } 
           } 
  ]
  ....
  ....

2)3)对于您的第2和第3个问题,navigationview是解决方案。  由M-x发布的解决方案很棒,但它是非常先进的示例&一开始也很难理解。

以下是来自Sencha Docs的navigatioview //create the navigation view and add it into the Ext.Viewport var view = Ext.Viewport.add({ xtype: 'navigationview', //we only give it one item by default, which will be the only item in the 'stack' when it loads items: [ { //items can have titles title: 'Navigation View', padding: 10, //inside this first item we are going to add a button items: [ { xtype: 'button', text: 'Push another view!', handler: function() { //when someone taps this button, it will push another view into stack view.push({ //this one also has a title title: 'Second View', padding: 10, //once again, this view has one button items: [ { xtype: 'button', text: 'Pop this view!', handler: function() { //and when you press this button, it will pop the current view (this) out of the stack view.pop(); } } ] }); } } ] } ] });

{{1}}