[英]How to display JSON form fields in ExtJS Tabpanel?
I am getting form fields from the database. 我从数据库中获取表单字段。 I need to create tabs dynamically and need to display fields inside those tabs based on the index.
我需要动态创建标签,并需要根据索引在这些标签内显示字段。
Example:
例:
The variable matrix length is 4. It should create 4 tabs. 可变矩阵长度为4。应创建4个标签。 matrix[0] contents should go to first tab.
matrix [0]的内容应转到第一个选项卡。 matrix[1] contents should go to second tab.
matrix [1]的内容应转到第二个选项卡。 matrix[2] contents should go to third tab and matrix[3] contents should go to fourth tab.
矩阵[2]的内容应转到第三个选项卡,矩阵[3]的内容应转到第四个选项卡。
var matrix = [
[{
"allowBlank": false,
"xtype": "textfield",
"fieldLabel": "Full Name <span class=\"red\">*</span>",
"labelWidth": 180,
"width": 500,
"labelAlign": "left",
"name": "refDataName",
"fieldsetId": 1,
"colspan": 1,
"maxLength": 100
}, {
"xtype": "textfield",
"fieldLabel": "First Name",
"labelWidth": 180,
"width": 500,
"labelAlign": "left",
"name": "refDataOne",
"fieldsetId": 1,
"colspan": 1,
"maxLength": 100
}, {
"xtype": "textfield",
"fieldLabel": "Last Name",
"labelWidth": 180,
"width": 500,
"labelAlign": "left",
"name": "refDataTwo",
"fieldsetId": 1,
"colspan": 1,
"maxLength": 100
}],
[{
"xtype": "textfield",
"fieldLabel": "Parent Name",
"labelWidth": 180,
"width": 500,
"labelAlign": "left",
"name": "refDataThree",
"fieldsetId": 2,
"colspan": 1,
"maxLength": 100
}],
[{
"xtype": "textfield",
"fieldLabel": "Address",
"labelWidth": 180,
"width": 500,
"labelAlign": "left",
"name": "refDataFive",
"fieldsetId": 3,
"colspan": 1,
"maxLength": 100
}],
[]
];
Thanks for your help. 谢谢你的帮助。
Your code is making multiple tabpanels inside the view. 您的代码在视图内制作了多个选项卡。 Remove the following code:
删除以下代码:
object['xtype'] = "tabpanel";
And add the object
to the tabpanel
. 并将
object
添加到tabpanel
。
Ext.application({ name: 'Fiddle', launch: function() { var matrix = [ [ { "allowBlank": false, "xtype": "textfield", "fieldLabel": "Full Name <span class=\\"red\\">*</span>", "labelWidth": 180, "width": 500, "labelAlign": "left", "name": "refDataName", "fieldsetId": 1, "colspan": 1, "maxLength": 100 }, { "xtype": "textfield", "fieldLabel": "First Name", "labelWidth": 180, "width": 500, "labelAlign": "left", "name": "refDataOne", "fieldsetId": 1, "colspan": 1, "maxLength": 100 }, { "xtype": "textfield", "fieldLabel": "Last Name", "labelWidth": 180, "width": 500, "labelAlign": "left", "name": "refDataTwo", "fieldsetId": 1, "colspan": 1, "maxLength": 100 } ], [ { "xtype": "textfield", "fieldLabel": "Parent Name", "labelWidth": 180, "width": 500, "labelAlign": "left", "name": "refDataThree", "fieldsetId": 2, "colspan": 1, "maxLength": 100 } ], [ { "xtype": "textfield", "fieldLabel": "Address", "labelWidth": 180, "width": 500, "labelAlign": "left", "name": "refDataFive", "fieldsetId": 3, "colspan": 1, "maxLength": 100 } ], [] ]; var tabpanel=Ext.create('Ext.tab.Panel', { renderTo: document.body, }); for (var z = 0; z < matrix.length; z++) { if(matrix[z].length > 0) { object = {}; object['title'] = "Form - " +z; object['layout'] = {type: "table", columns: 2}; object['defaults'] = {anchor: "100%", bodyStyle: "padding:40px", labelStyle: "padding-left: 45px"}; object['collapsible'] = true; object['items'] = matrix[z]; tabpanel.add(object); } } } });
<link rel="stylesheet" href="https://cdn.sencha.com/ext/gpl/4.1.1/resources/css/ext-all.css"> <script type="text/javascript" src="https://cdn.sencha.com/ext/gpl/4.1.1/ext-all-debug.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.