2014-10-18 29 views
0

我想用sencha touch发送发布请求,我想发布的参数是动态的,即我想将textField值作为参数发布。请帮我Sencha Touch代理发送带有动态参数的发布请求

proxy: { 
    type: "ajax", 
     url:'http://anotherserver.com/query.php', 
     method:'post', 
    extraParams: { 
     val: "TextField1.Text" // **here I want to provide the value of the textField help me plz** 
    }, 
    reader: { 
     type: "json", 
     rootProperty: "notes", 
     totalProperty: "total" 
    } 
}, 

回答

0

通常你想把文本字段包装在一个窗体(formpanel)中。 这时你可以先使用

var form = Ext.Viewport.down('.formpanel'), 
    values = form.getValues(), 
    textfieldValue = values.textfield_name; 
... 
extraParams: { 
    val: textfieldValue 
}, 
1

查找煎茶触摸模式的概念,因为你可以沿着你的模型代码到你的表格(Ext.FormPanel),并把它作为一个。

var model = Ext.create('Ext.data.Model',{ 
    fields: ['name', 'email', 'password'], 
    proxy: [] //your proxy settings here, 
    customFunctionWithAjax: function(){ 
    } 

}); 

var form = 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' 
     } 
    ] 
}); 
//after filling up your form you can get all textfields value 
//with .getValues() and set it to your model 

model.setData(form.getValues); 
//then you can do anything you want like SAVE, or update 
model.save(); 
//or call your custom function with your customised ajax request 
model.customFunctionWithAjax(); 
// you can also check if your data are correct before sending it using .validate(); 
model.validate();