ExtJS如何从后台获取数据 5
在做报表时,我把JQUERY的异步加载,本来以为会返回一个JSON数组,可是程序却总跑不起来,估计EXTJS不允许这种语法,前辈们能发一份完整的语法或代码给我吗?谢谢...
在做报表时,我把JQUERY的异步加载,本来以为会返回一个JSON数组,可是程序却总跑不起来,估计EXTJS不允许这种语法,前辈们能发一份完整的语法或代码给我吗?谢谢
展开
推荐于2017-12-07 · 知道合伙人互联网行家
关注
展开全部
1.定义一个formpanel。
var editForm = Ext.create('Ext.form.Panel', {
bodyPadding: 5,
width: 350,
border: false,
frame: true,
xtype: 'filedset',
url: 'ecAssetStatus/update',
layout: 'anchor',
defaults: {
anchor: '100%'
},
defaultType: 'textfield',
items: [{
name: 'id',
fieldLabel: 'id',
hidden: true
},{
fieldLabel: '名字',
name: 'name',
emptyText: '名字',
allowBlank: false
},{
fieldLabel: '描述',
xtype: 'textarea',
name: 'description',
allowBlank: false
}],
buttons: [{
text: '确定',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
success: function(form, action) {
Ext.Msg.alert('提示', action.result.msg);
store.load();
}
});
}
}
}]
});
2.定义一个window.Window
var win2 = Ext.create('Ext.window.Window',{
title: '修改',
hight: 400,
width:400,
//frame: true,
hidden: true,
layout: 'fit',
closable: true,
closeAction: 'hide',
//animateTarget:this,
items: editForm
});
3.在点击“操作”按钮的时候得到后台的得值,并把值在editForm里面load一下。
editForm.getForm().load({
url: 'ecAssetStatus/show?id='+selected1[0].get('id'),
waitMsg: '请稍后......'
})
win2.show()
4.json数据格式
{"success":"true","data":{"id":"49","name":"12344553252","description":"adffafdadf"}}
格式很重要,格式正确才能够在form里面读出来。
var editForm = Ext.create('Ext.form.Panel', {
bodyPadding: 5,
width: 350,
border: false,
frame: true,
xtype: 'filedset',
url: 'ecAssetStatus/update',
layout: 'anchor',
defaults: {
anchor: '100%'
},
defaultType: 'textfield',
items: [{
name: 'id',
fieldLabel: 'id',
hidden: true
},{
fieldLabel: '名字',
name: 'name',
emptyText: '名字',
allowBlank: false
},{
fieldLabel: '描述',
xtype: 'textarea',
name: 'description',
allowBlank: false
}],
buttons: [{
text: '确定',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
success: function(form, action) {
Ext.Msg.alert('提示', action.result.msg);
store.load();
}
});
}
}
}]
});
2.定义一个window.Window
var win2 = Ext.create('Ext.window.Window',{
title: '修改',
hight: 400,
width:400,
//frame: true,
hidden: true,
layout: 'fit',
closable: true,
closeAction: 'hide',
//animateTarget:this,
items: editForm
});
3.在点击“操作”按钮的时候得到后台的得值,并把值在editForm里面load一下。
editForm.getForm().load({
url: 'ecAssetStatus/show?id='+selected1[0].get('id'),
waitMsg: '请稍后......'
})
win2.show()
4.json数据格式
{"success":"true","data":{"id":"49","name":"12344553252","description":"adffafdadf"}}
格式很重要,格式正确才能够在form里面读出来。
展开全部
我写了个简单的grid,后台能正常获取数据,但是前台无法获得
后台代码:
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext db=new DataClassesDataContext ();
var query = from p in db.newpo select new { p.new_poid, p.new_subject, createdon=p.createdon.ToString()};
string josn = query.ToJSON();
Response.Write(josn);
}
}
}
数据在页面上打印出来为:
[{"new_poid":"000dabf7-e3b3-df11-8580-0003ff1da946","new_subject":"有方案活动","createdon":"08 30 2010 3:09AM"},{"new_poid":"109a3a27-d8b4-df11-8580-0003ff1da946","new_subject":"test--ssss","createdon":"08 31 2010 8:17AM"},{"new_poid":"70015047-a6bc-df11-920c-0003ff1da946","new_subject":"test-09-10","createdon":"09 10 2010 6:40AM"}]
前台代码:
XML/HTML code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>test</title>
<!-- <meta http-equiv="Content-Type" content="text/html; charset="UTF-8" />-->
<link href="Css/ext-all.css" rel="stylesheet" type="text/css" />
<script src="Script/ext-base.js" type="text/javascript"></script>
<script src="Script/ext-all.js" type="text/javascript"></script>
<script type="text/javascript">
Ext.onReady(function() {
var ds= new Ext.data.JsonStore({
url:'Default.aspx',
autoLoad:true,
fields: [
{ name: 'new_poid' },
{ name: 'new_subject' },
{ name: 'createdon' }
]
});
var grid = new Ext.grid.GridPanel({
loadMask: { msg: '正在加载数据,请稍侯……' },
renderTo: 'grid',
height: 250,
store:ds,
width: 350,
colModel: new Ext.grid.ColumnModel([
{ header: '编号', dataIndex: 'new_poid' },
{ header: '名称', dataIndex: 'new_subject' },
{ header: '日期', dataIndex: 'createdon' }
])
});
})
</script>
</head>
<body>
<div id="grid"></div>
</body>
</html>
运行后显示不出数据,也不报错,我把后台的数据直接在前台赋值是可以显示的,说明后台数据格式没错,但是就是不能正常获取,请求帮助
后台代码:
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext db=new DataClassesDataContext ();
var query = from p in db.newpo select new { p.new_poid, p.new_subject, createdon=p.createdon.ToString()};
string josn = query.ToJSON();
Response.Write(josn);
}
}
}
数据在页面上打印出来为:
[{"new_poid":"000dabf7-e3b3-df11-8580-0003ff1da946","new_subject":"有方案活动","createdon":"08 30 2010 3:09AM"},{"new_poid":"109a3a27-d8b4-df11-8580-0003ff1da946","new_subject":"test--ssss","createdon":"08 31 2010 8:17AM"},{"new_poid":"70015047-a6bc-df11-920c-0003ff1da946","new_subject":"test-09-10","createdon":"09 10 2010 6:40AM"}]
前台代码:
XML/HTML code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>test</title>
<!-- <meta http-equiv="Content-Type" content="text/html; charset="UTF-8" />-->
<link href="Css/ext-all.css" rel="stylesheet" type="text/css" />
<script src="Script/ext-base.js" type="text/javascript"></script>
<script src="Script/ext-all.js" type="text/javascript"></script>
<script type="text/javascript">
Ext.onReady(function() {
var ds= new Ext.data.JsonStore({
url:'Default.aspx',
autoLoad:true,
fields: [
{ name: 'new_poid' },
{ name: 'new_subject' },
{ name: 'createdon' }
]
});
var grid = new Ext.grid.GridPanel({
loadMask: { msg: '正在加载数据,请稍侯……' },
renderTo: 'grid',
height: 250,
store:ds,
width: 350,
colModel: new Ext.grid.ColumnModel([
{ header: '编号', dataIndex: 'new_poid' },
{ header: '名称', dataIndex: 'new_subject' },
{ header: '日期', dataIndex: 'createdon' }
])
});
})
</script>
</head>
<body>
<div id="grid"></div>
</body>
</html>
运行后显示不出数据,也不报错,我把后台的数据直接在前台赋值是可以显示的,说明后台数据格式没错,但是就是不能正常获取,请求帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var dataStore = new Ext.data.Store({
baseParams:{method:'query',sql:'feerate_list'},
proxy:new Ext.data.HttpProxy({url:'../ft.service'}),
reader:new Ext.data.XmlReader(
{record: 'record',id:'id',totalProperty:'totalCount'},
[
'id','unit','unitvalue','discount','finalvalue',
'name','num','addid','addtime','addname'
]
)
});
dataStore.load({params:{start:0,limit:20}});
更多追问追答
追答
你用的struts2 ?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
333333333333333333333333333333333ffffffffffffff
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询