ExtJS的FormPanel中的组件使用load加载远程的JSON数据的方法

转自:http://www.itzhai.com/extjs-formpanel-components-of-load-using-the-load-method-of-a-remote-json-data.html



在创建FormPanel时,指定一个reader,下面在reader配置项中创建了一个JsonReader去解析服务器端返回的Json数据,JsonReader中使用mapping把对应的name中的值映射到表格对应的组件中:

var formPanel = new Ext.form.FormPanel({
	labelAlign: 'right',
	labelWidth: 100,
	frame: true,
	width: 685,
	layout:'form',
	fileUpload: true,
	defaultType: 'textfield',
	defaults: {width:200},
	reader: new Ext.data.JsonReader({root:'product'},
			[{name:'productId',mapping:'productId'},
			 {name:'name',mapping:'name'},				 
			 {name:'typecom',mapping:'typecom'},
			 {name:'baseprice',mapping:'baseprice'},
			 {name:'marketprice',mapping:'marketprice'},
			 {name:'sellprice',mapping:'sellprice'},
			 {name:'code',mapping:'code'},
			 {name:'brandCode',mapping:'brandCode'},
			 {name:'sexrequest',mapping:'sex'},				 
			 {name:'model',mapping:'model'},
			 {name:'weight',mapping:'weight'},
			 {name:'buyexplain',mapping:'buyexplain'},
			 {name:'description',mapping:'description'}]),
	items: [{
		xtype:'hidden',
		name:'productId',
	},{
		fieldLabel: '产品名称',
		name: 'name',
		id: 'name',
		allowBlank: false
	},com_productType ,{
		fieldLabel: '采购价',
		name: 'baseprice',
		id: 'baseprice',
		allowBlank: false
	},{
		fieldLabel: '市场价',
		name: 'marketprice',
		id: 'marketprice',
		allowBlank: false
	},{
		fieldLabel: '销售价',
		name: 'sellprice',
		id: 'sellprice',
		allowBlank: false
	},{
		fieldLabel: '货号',
		name: 'code',
		id: 'code',
		allowBlank: false
	},com_brand, com_sex,{
		fieldLabel: '型号',
		name: 'model',
		id: 'model',
		allowBlank: false
	},{
		fieldLabel: '重量',
		name: 'weight',
		id: 'weight',
		allowBlank: false
	},{
		fieldLabel: '购买说明',
		name: 'buyexplain',
		id: 'buyexplain',
		allowBlank: false
	},{
		xtype: 'htmleditor',
		name: 'description',
		fieldLabel: '产品介绍',
		width: 600,
		height:150,
		allowBlank: false
	}]
});

然后在创建和显示formPanel的地方调用formPanel的load方法,向服务器请求数据,然后加载到formPanel中:

formPanel.form.load({
	url:'product/Product-getProductById.action?productId='+productId
});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值