我正在extjs中实现项目.我对extjs很新.我用两个Textfields Question和Option创建了视图,并创建了两个按钮ok和cancel.
我的观点代码:
Ext.create('Ext.form.Panel', {
    title: 'Question-option',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),        
    items: [{
        xtype: 'textfield',
        name: 'Question',
        fieldLabel: 'Question',
        allowBlank: false  // requires a non-empty value
    }, {
        xtype: 'textfield',
        name: 'Option',
        fieldLabel: 'Option',
        vtype: 'Option'  // requires value to be a valid email address format
    },
    {xtype: 'button', text: 'Ok'}, 
    {xtype: 'button', text: 'Cancel'}
 ]
});
在确定按钮上单击我想将这些文本字段数据添加到商店.
所以,请你建议我如何编写buttonclick事件,将所有这些文本字段数据添加到商店.
以这家商店为例:
Ext.define ('model', {
  extend: 'Ext.data.Model' ,
  fields: ['Question', 'Option']
});
var store = Ext.create ('Ext.data.Store', {
  model: 'model'
});
// Handler called on button click event
function handler (button) {
  var form = button.up('form').getForm ();
  // Validate the form
  if (form.isValid ()) {
    var values = form.getFieldValues ();
    store.add ({
      Question: values.Question ,
      Option: values.Option
    });
  }
  else {} // do something else here
}
您将获得表单数据,然后将这些数据添加到商店.
Cyaz
| 归档时间: | 
 | 
| 查看次数: | 16560 次 | 
| 最近记录: |