本文介绍了extjs - 在表单中嵌入对象/名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用多个对象来使用 setValues() 填充 extjs 表单的一部分.例如:

I currently use multiple objects to populate parts of a extjs form using setValues(). Ex:

someForm.getForm().setValues({prop1: foo}); 

有没有一种方法可以为我的表单元素命名 object1.prop1object2.prop2 等.这样我就可以做单个 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之前拦截上传到map(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 - 在表单中嵌入对象/名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 21:55