87,989
社区成员
发帖
与我相关
我的任务
分享Ext.onReady(function(){
Ext.QuickTips.init();
var productForm=Ext.create('Ext.form.Panel',{
title:'表单加载数据示例',
width:300,
frame:true,
fieldDefaults:{
labelSeparator:':',
labelWidth:80,
width:200
},
renderTo:'form',
items:[
{
fieldLabel:'产品名称',
xtype:'textfield',
name:'productName',
value:'U盘'
},{
fieldLabel:'金额',
xtype:'numberfield',
name:'price',
value:'100'
},{
fieldLabel:'生产日期',
xtype:'datefield',
format:'Y年m月j日',
value:new Date(),
name:'date'
},{
fieldLabel:'产品简介',
xtype:'textarea',
name:'introduction'
},{
xtype:'hidden',
name:'productId',
value:'001'
}
],
buttons:[
{
text:'加载简介',
handler:loadIntroduction
}
]
});
//表单加载的回调函数
function loadIntroduction(){
var params=productForm.getForm().getValues();
productForm.getForm().load({
params:params, //传递函数
url:'productServer.jsp',
method:'GET',
success:function(form,action){
Ext.Msg.alert('提示','产品简介加载成功');
},
failure:function(form,action){
Ext.Msg.alert('提示','产品简介加载失败<br>失败原因:'+action.result.errorMessage);
}
});
}
});<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="extjs4.0/resources/css/ext-all.css">
<script type="text/javascript" src="extjs4.0/bootstrap.js"></script>
<script type="text/javascript" src="extjs4.0/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="form.js"></script>
<title>examples of ExtJs' forms</title>
</head>
<body>
<div id='form'></div>
</body>
</html><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String productId=request.getParameter("productId");
if("001".equals(productId)){
String msg="{success:true,data:{introduction:'本产品美观实用'}}";
response.getWriter().write(msg);
}else{
String msg="{success:false,errorMessage:'数据不存在'}";
response.getWriter().write(msg);
}
%>
</body>
</html>String msg="{success:true,data:{introduction:'本产品美观实用'}}";
response.getWriter().write(msg);