我试图通过使用WCF服务返回的JSON字符串来加载Flexigrid.
我的服务有一个public string GetContacts(string CustomerID)方法,它返回一个Json字符串.
通过使用System.Web.Script.Serialization.JavaScriptSerializer类从List对象创建JSON字符串
.所以,我的目标是将JSON字符串绑定到我的Flexigrid作为对象.我使用Web服务结果转换为对象
var customer = eval("("+result+")");
Run Code Online (Sandbox Code Playgroud)
结果是从服务返回JSON字符串.有没有办法将客户对象绑定到Flexigrid?
alm*_*ori 19
Flexigrid在json中需要如下格式
编辑感谢EAMann的格式更新.
total: (no of rec)
page : (page no)
rows : [{cell: [ (col1 value) , (col2 value) ,.. ] },
{cell: [ (col1 value) , (col2 value) ,.. ] }]
Run Code Online (Sandbox Code Playgroud)
为了将数据绑定到网格,我更喜欢通过网络发送数据,然后在客户端上格式化它,但那只是我继承人的一个例子
function formatCustomerResults(Customers){
var rows = Array();
for (i = 0; i < Customers.length; i++) {
var item = Customers[i];
//Do something here with the link
var link = "alert('opening item " + item.DealGuid + "');"
rows.push({ cell: [item.DealId,
item.Created,
item.CurrentStatus,
item.LastNote,
'<a href="javascript:void(0);" onclick="' + link + '" >view</a>']
});
}
return {
total: Customers.length,
page: 1,
rows: rows
};
}`
Run Code Online (Sandbox Code Playgroud)
然后你需要的只是
$("#FlexTable").flexAddData(formatCustomerResults(eval(data)));
Run Code Online (Sandbox Code Playgroud)
ps这最后一位是jquery语法