我从数据库中获取表单字段。我需要动态创建标签,并且需要根据索引显示这些标签内的字段。
示例:
变量矩阵长度为4.它应该创建4个制表符。 matrix [0]内容应该转到第一个标签。 matrix [1]内容应该转到第二个标签。矩阵[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
}],
[]
];
感谢您的帮助。
答案 0 :(得分:1)
您的代码在视图中制作了多个tabpanel。删除以下代码:
object['xtype'] = "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);
}
}
}
});
&#13;
<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>
&#13;