问题描述
我目前使用多个对象使用 setValues()
来填充extjs表单的部分。例如:
I currently use multiple objects to populate parts of a extjs form using setValues()
. Ex:
someForm.getForm().setValues({prop1: foo});
有没有办法我可以命名我的表单元素 object1.prop1
, object2.prop2
ect。所以我可以做单个 someForm.getForm()。setValues({object1:object1,object2:object2,...})
?即嵌入的对象将被解析出来。
Is there a way I could name the elements of my form object1.prop1
, object2.prop2
ect. so that I could do single someForm.getForm().setValues({object1: object1, object2: object2, ...})
? i.e. the embedded objects would be parsed out.
此外,是否有一种方法可以在 POST
之前截取上传内容( object1.prop1
, object1.prop2
, ...
) - > object1:{prop1:*,prop2:*,...}
?
Additionally, is there a way to intercept the upload before the POST
to map (object1.prop1
, object1.prop2
, ...
) --> object1: {prop1: *, prop2: *, ...}
?
这将使得它比做一些像映射 object1.prop1
- > object1_prop1
- > object1.prop1
This would make it much easier than having to do something like mapping object1.prop1
--> object1_prop1
-> object1.prop1
感谢您提供的任何帮助
推荐答案
是的,你可以这样做,但是与你所指定的方式不一样。
有两种情况:
Yes, you can do so but the way is different than the one you have specified in question.There would be two scenarios :
1)您有一个表单(假设修改),并且向服务器请求获取数据。
您可以做的是创建一个具有分配名称到表单域的模型。并使用服务器的值分配模型以形成。见下面例如
1) You have a form(suppose modify), and you make a request to server to get the data.What you can do is create a model with assigned name to the form fields. And assign the model to form with values from server. See below e.g.
// define StudentModel with fields firstName, lastName, address, and so on....
// form with fields, please have field attribute 'name' with values defined in model
// e.g. {xtype : 'textfield', name: 'firstName'}, {xtype : 'textfield', name: 'lastName'}, and so on
var form = this.getForm();
form.reader = Ext.create('Ext.data.reader.Json',{ // Use XML reader if you are using XML response.
success: '@success',
model: 'StudentModel'
});
form.load({ // load method will load data automatically from server to form fields
url: '/getStudentData',
params:{
studentId: 24
}
});
2)其他情况是,您可以在本地使用数据(假设为数组或变量),而您想分配该数据以形成
使用StudentModel创建一个记录如下,并分配记录形式:
2) Other scenario is you have data available locally(suppose in array or variables) and you want to assign that data to form,Create a record with StudentModel as below, and assign record to form :
var record = Ext.create('StudentModel', {
firstName: 'Nandkumar',
lastName: 'Tekale',
address: 'RH 26, some street, city'
});
form.loadRecord(record); // You are done, all values to form are assigned.
这篇关于extjs - 表单中嵌入的对象/名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!