关于WijGrid的远程数据问题:
从下载的例子中和http://wijmo.com/demo/explore/上我了解到了,
wijGrid从一个网址取数据有两种格式:
1.http://wijmo.com/demo/explore/?w ... e%20custom%20paging中的OData方式,
data: new wijmo.data.ODataView("http://services.odata.org/V2/Northwind/Northwind.svc/Products", {
ajax: { dataType: "jsonp" },
pageSize: 10
}),
columnsAutogenerationMode: "none",
columns: [
{ dataKey: "roductID", headerText: "roductID", dataType: "number", dataFormatString: "d" },
{ dataKey: "roductName", headerText: "roductName" },
{ dataKey: "UnitPrice", headerText: "UnitPrice", dataType: "currency" },
{ dataKey: "UnitsInStock", headerText: "UnitsInStock", dataType: "number", dataFormatString: "d" },
{ dataKey: "Discontinued", headerText: "Discontinued", dataType: "boolean" }
]
});
直接键入网址http://services.odata.org/V2/Northwind/Northwind.svc/Products后了解到了,OData是一种
序列化对象的XML格式。后来本人下载了AspNet.WebApi.OData包,但是由于缺少wijmo.data.ajax.js文件,只好作罢!
2.下载到本地的Wijmo示例中的Grid/DataSources.cshtml中有:
data: new wijdatasource({
proxy: new wijhttpproxy({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
username: "demo",
featureClass: "",
style: "full",
maxRows: 5,
name_startsWith: "ab"
},
key: "geonames"
}),
reader: new wijarrayreader([
{ name: "label", mapping: function (item) { return item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName } },
{ name: "name", mapping: "name" },
{ name: "countryCode", mapping: "countryCode" },
{ name: "continentCode", mapping: "continentCode" }
])
})
通过键入网址http://www.geonames.org/searchJSON?username=demo了解到了WijGrid需要的Json格式。
3.之后,我开始仿照第二种格式,首先在页面js中加入:
data: new wijdatasource({
proxy: new wijhttpproxy({
url: "@mypath",
dataType: "jsonp",
data: {
},
key: "addresses"
}),
reader: new wijarrayreader([
{ name: "name", mapping: "name" },
{ name: "address", mapping: "address" }
])
})
从网址@path中我可以取到数据:{"totalResultsCount":3,"addresses":[{"Id":16,"Ip":"::1","UserId":0,"UserName":null,"name":null,"address":"兰州城关","phone":"1234567","phone2":null,"status":false},{"Id":17,"Ip":"::1","UserId":0,"UserName":null,"name":null,"address":"兰州西固","phone":"1234567","phone2":null,"status":false},{"Id":18,"Ip":"::1","UserId":0,"UserName":null,"name":null,"address":"兰州安宁","phone":"1234567","phone2":null,"status":false}]}
但是我的页面Grid中没有显示。
我的问题是:如何通过Jsonp的方式将数据加入到C1Grid中呢? |
|