extJS如何通过按钮发布参数?

时间:2011-05-23 07:57:19

标签: extjs

我有这个代码。如果我单击按钮,我的表单参数将插入到数据库中。我怎么能这样做?我应该写什么? 如果我点击重置表单,我的窗口关闭。请帮忙!谢谢!

    var AddQuestion = new Ext.Button({
        method      : 'POST',
        url         : '/questions/create',
        tooltip     : 'Add Question',
        icon        : '/images/icons/silk/add.png',
        iconCls     : 'add',
        style       : 'margin-right: 60px;float:right;',
        handler     : function() {
                  new Ext.Window({
                    title       : 'Add Question',
                    width       : 700,
                    height      : 800,  
                    bodyStyle   : 'padding: 10px',                      
                    layout       : 'form',
                    modal       : true,
                    closable    : true,
                    resizable   : false,                              
                    draggable   : false,
                    autowidth   : true,
                    items       :[
                                    { 
                                        fieldLabel      : 'Question', 
                                        name            : 'question[text]',
                                        xtype           : 'htmleditor', 
                                        enableFont      : false,
                                        enableFormat    : false,
                                        enableFontSize  : false,
                                        enableLists     : false,
                                        enableAlignments: false,
                                        enableFont      : false,
                                        enableColors    : false,
                                        height          : 160,
                                        width           : 560               
                                    },
                                     {
                                         name           :'form_type',
                                         fieldLabel     :'Form Type',
                                         xtype          :'combo',
                                         triggerAction  :'all',
                                         mode           :'local',
                                         editable       : false,
                                         allowBlank     : false,
                                         emptyText      :'You should Choose any...',
                                         store          :new Ext.data.SimpleStore({
                                         fields         :['mode', 'name'],
                                         data           :[
                                                         ['1', 'TextArea Question'], 
                                                         ['2', 'Scale Question'], 
                                                         ['3', 'TextArea + Scale Question']
                                         ]
                                         }),
                                         displayField   :'name',
                                         valueField     :'mode',
                                         hiddenName     :'form_type'
                                         }, 
                                        {
                                            xtype               : 'itemselector',
                                            name                : 'selected_respondents',                       
                                            imagePath           : '../ux/images/',
                                            bodyStyle               : 'background:#DFE8F6',
                                                    multiselects: [{
                                                        legend        : 'All Respondents',
                                                        width         : 270,
                                                        height        : 350,
                                                        store         : st,
                                                        displayField  : 'email',
                                                        valueField    : 'id',
                                                        hiddenName    : 'email'                                    
                                                    },{
                                                        legend        : 'Selected Respondents',             
                                                        width         : 270,
                                                        height        : 350,
                                                        store         : st2,
                                                        displayField  : 'email',
                                                        valueField    : 'id',
                                                        hiddenName    : 'email' 
                                                    }]
                                            },  
                                            {
                                            fieldLabel      :'To do',
                                            xtype           : 'button',
                                            text            : 'Refresh respondents ↑',
                                            height          : 30,               
                                            icon            : '/images/icons/silk/arrow_refresh_small.png',
                                            width           : 180,
                                            handler: function(){
                                                if((who_is_admin == '1') || (who_is_admin == '0')){
                                                    if (st2.getCount() == 0){
                                                        st.reload();
                                                    }else
                                                    {
                                                      Ext.Msg.show({
                                                          title         : 'Message for You',
                                                          msg           : "You should left <i>'Selected Respondents'</i> field empty to <b>refresh</b> some changes!",
                                                          modal         : true,
                                                          Height        : 200,
                                                          closable      : true,
                                                          resizable     : false,                              
                                                          draggable     : false,          
                                                          Width         : 300,
                                                          buttons       : Ext.Msg.OK
                                                      });                                   
                                                    }
                                        }
                                }

                        },
                        {
                        xtype       : 'checkbox',
                        boxLabel    : 'Make Question Active',
                        inputValue  : '1',
                        name        : 'is_active',
                        hiddenName  : 'is_active',
                        checked     : true
                      },                                                                                
                    ],
                    buttons: [{
                    text: 'Reset Form',
                    handler: function(){
                        }
                    },{
                    text: 'Submit Form',
                    handler: function(){

                        }
                    }
            }] // button end
                  }).show();  //show window
                }

    });     

1 个答案:

答案 0 :(得分:1)

您可以在用户点击按钮后立即发送AJAX请求。 例如,在您的情况下,“提交表单”按钮的处理程序应该类似于

Ext.Ajax.request({
     url:'assertion.htm', // url of page where you want to send it
     method: 'POST',          
     params: {
          selectedSource:source.getValue() //Right hand side whatever value you want to send
     },
     scope:this
});