define(function (require) { var $dynamicDiv, pcontext; function buildForm(props) { var items = []; for (var i = 0; i < props.length; i++) { var prop = props[i]; var item = { name: prop.lotField, label: prop.lotName }; switch ($.trim(prop.lotAttFlag)) { case '1': item.disabled = true; break; case '2': item.required = true; break; case '3': item.required = false; break; case '4': item.readonly = true; break; } switch ($.trim(prop.lotType)) { case '1': item.xtype = 'textbox'; break; case '2': item.xtype = 'numberbox'; break; case '3': item.xtype = 'datebox'; break; case '4': item.xtype = 'datetimebox'; break; default: item.xtype = 'textbox'; break; } if ($.trim(prop.lotValue)) { item.xtype = 'combobox'; item.data = $.yvan.bizDict(prop.lotValue).combo(); } //items.push($.extend({}, $.fn[item.xtype].defaults, item)); items.push(item); } $dynamicDiv.empty(); $dynamicDiv.power('renderEach', { $target: $dynamicDiv, items: [items], context: pcontext }); } return function (context) { var pcontext = context; return { center: { border: false, items: [ { xtype: 'toolbar', title: '动态表单', items: [ { text: '表单1', onClick: function () { $.yvan.ajax({ url: whUrl('/lotAttributesRule/queryLotAttributesRuleDetail'), data: { lotRuleId: 'LOT00000005' }, success: function (data) { buildForm(data.data); } }); } }, { text: '表单2', onClick: function () { $.yvan.ajax({ url: whUrl('/lotAttributesRule/queryLotAttributesRuleDetail'), data: { lotRuleId: 'LOT00000006' }, success: function (data) { buildForm(data.data); } }); } }, { text: '表单3', onClick: function () { $.yvan.ajax({ url: whUrl('/lotAttributesRule/queryLotAttributesRuleDetail'), data: { lotRuleId: 'LOT00000007' }, success: function (data) { buildForm(data.data); } }); } } ] }, { onRender: function () { $dynamicDiv = $(this); }, xtype: 'form' }, [ { xtype: 'offset' }, { xtype: 'button', text: '提交', onClick: function () { var vr = $dynamicDiv.formGet(true); console.log(vr); } }, { xtype: 'button', text: '清空', onClick: function () { $dynamicDiv.formClear(); } } ] ] } }; }; } );