我想利用ExtJS来调用WebService来做一个GridPanel.
我的WebService是using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BLL;namespace ExtJs_Demo
{
/// <summary>
/// PttGetData 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class PttGetData : System.Web.Services.WebService
{ CancelAfterVerify cav = new CancelAfterVerify(); [WebMethod]
public List<PttCmd> CancelableTerminal()
{
List<PttCmd> setOfTerminId = new List<PttCmd>(cav.qryCancelableTerminal());
return setOfTerminId;
}
}
}我的JavaScript语句是
function f() {
Ext.Ajax.request({
url: 'PttGetData.asmx/CancelableTerminal', // Webservice的地址以及方法名
method: 'POST', // poste 方式传递
success: onSuccess });
} function onSuccess(request, options) { var result = Ext.util.JSON.decode(request.responseText);
Ext.Msg.alert('Result', request.responseText);
}
这个JS的写法.如果我从WebService中传一个String类型的值出来就能够正常弹出MSSAGEBOX和内容..但是我现在要从WebService传一个LIST到页面. 这个JS就拿不到了.. 我应该怎样写呢?? 我看了ExtJS官网上的例子.. 它是用这样的写法来设置数据源.
Ext.onReady(function() {
//creat the proxy
var proxy = new Ext.data.HttpProxy({url:'../PttGetData.asmx/Helloworld'});
//creat reader
var reader = new Ext.data.JsonReader({},[{name:'Terminal ID',mapping:'TermId'}]);
//data source
var store = new Ext.data.Store({
proxy:proxy,
reader:reader
});
});
大家帮我看看应该怎样改??? 谢谢了
我的WebService是using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BLL;namespace ExtJs_Demo
{
/// <summary>
/// PttGetData 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class PttGetData : System.Web.Services.WebService
{ CancelAfterVerify cav = new CancelAfterVerify(); [WebMethod]
public List<PttCmd> CancelableTerminal()
{
List<PttCmd> setOfTerminId = new List<PttCmd>(cav.qryCancelableTerminal());
return setOfTerminId;
}
}
}我的JavaScript语句是
function f() {
Ext.Ajax.request({
url: 'PttGetData.asmx/CancelableTerminal', // Webservice的地址以及方法名
method: 'POST', // poste 方式传递
success: onSuccess });
} function onSuccess(request, options) { var result = Ext.util.JSON.decode(request.responseText);
Ext.Msg.alert('Result', request.responseText);
}
这个JS的写法.如果我从WebService中传一个String类型的值出来就能够正常弹出MSSAGEBOX和内容..但是我现在要从WebService传一个LIST到页面. 这个JS就拿不到了.. 我应该怎样写呢?? 我看了ExtJS官网上的例子.. 它是用这样的写法来设置数据源.
Ext.onReady(function() {
//creat the proxy
var proxy = new Ext.data.HttpProxy({url:'../PttGetData.asmx/Helloworld'});
//creat reader
var reader = new Ext.data.JsonReader({},[{name:'Terminal ID',mapping:'TermId'}]);
//data source
var store = new Ext.data.Store({
proxy:proxy,
reader:reader
});
});
大家帮我看看应该怎样改??? 谢谢了
用json吧
用json吧
我改了一下js的写法
Ext.onReady(function() { var store = new Ext.data.Store({
url: 'PttGetData.asmx/CancelableTerminal',
reader: new Ext.data.XmlReader({
record: 'PttCmd'
},
[{ name: 'TermId', mapping: 'PttCmd->TermId' }
])
}); var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{ header: "Terminal ID", width: 120, dataIndex: 'TermId', sortable: true }
],
renderTo: 'CAV',
width: 540,
height: 200
}); store.load();
});
这样子有点眉目了.. 但是只能读出一个PANEL..不能读出其中的数据..
−
<PttCmd>
<MsgTime>0001-01-01T00:00:00</MsgTime>
<TermId>GZ0026</TermId>
<MsgWay>0</MsgWay>
<IsSucc>0</IsSucc>
<T_isRec>0</T_isRec>
<T_IsCommit>0</T_IsCommit>
<SendTime>0001-01-01T00:00:00</SendTime>
<RecvTime>0001-01-01T00:00:00</RecvTime>
<CommitTime>0001-01-01T00:00:00</CommitTime>
<StartTime>0001-01-01T00:00:00</StartTime>
<EndTime>0001-01-01T00:00:00</EndTime>
<OperTime>0001-01-01T00:00:00</OperTime>
</PttCmd>
−
<PttCmd>
<MsgTime>0001-01-01T00:00:00</MsgTime>
<TermId>GZ5566</TermId>
<MsgWay>0</MsgWay>
<IsSucc>0</IsSucc>
<T_isRec>0</T_isRec>
<T_IsCommit>0</T_IsCommit>
<SendTime>0001-01-01T00:00:00</SendTime>
<RecvTime>0001-01-01T00:00:00</RecvTime>
<CommitTime>0001-01-01T00:00:00</CommitTime>
<StartTime>0001-01-01T00:00:00</StartTime>
<EndTime>0001-01-01T00:00:00</EndTime>
<OperTime>0001-01-01T00:00:00</OperTime>
</PttCmd>
−
<PttCmd>
<MsgTime>0001-01-01T00:00:00</MsgTime>
<TermId>SH1897</TermId>
<MsgWay>0</MsgWay>
<IsSucc>0</IsSucc>
<T_isRec>0</T_isRec>
<T_IsCommit>0</T_IsCommit>
<SendTime>0001-01-01T00:00:00</SendTime>
<RecvTime>0001-01-01T00:00:00</RecvTime>
<CommitTime>0001-01-01T00:00:00</CommitTime>
<StartTime>0001-01-01T00:00:00</StartTime>
<EndTime>0001-01-01T00:00:00</EndTime>
<OperTime>0001-01-01T00:00:00</OperTime>
</PttCmd>
</ArrayOfPttCmd>
我只需要拿到TermId 其它的都不需要..
好阿..
问题解决~
我的webservice改成这样写..namespace ExtJs_Demo
{
/// <summary>
/// PttGetData 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class PttGetData : System.Web.Services.WebService
{ CancelAfterVerify cav = new CancelAfterVerify(); [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json,
UseHttpGet = true, XmlSerializeString = false)] public List<PttCmd> CancelableTerminal()
{
List<PttCmd> setOfTerminId = new List<PttCmd>(cav.qryCancelableTerminal());
return setOfTerminId;
}
}
}
然后我的js改成这样子... 其实我的JS并没有多大的改变..只是把XMLREADER改为JSONSTORE
Ext.onReady(function() { var myStore = new Ext.data.JsonStore({
// Load data at once
autoLoad: true,
// Override default http proxy settings
proxy: new Ext.data.HttpProxy({
// Call web service method using GET syntax
url: 'PttGetData.asmx/CancelableTerminal',
// Ask for Json response
headers: { 'Content-type': 'application/json' }
}),
// Root variable
root: 'd',
// Record identifier // Fields declaration
fields: ['TermId']
}); var grid = new Ext.grid.GridPanel({
// Set store
store: myStore,
// Columns definition
columns: [
{ header: "Terminal ID", width: 300, dataIndex: 'TermId', sortable: true }
],
// Render grid to dom element with id set to panel
renderTo: 'CAV',
width: 800,
height: 400
});
myStore.load();});