我不明白这里发生了什么,但我认为它并没有正确理解架构。我已经尝试了很多不同的选项,表达架构的方式,我已经尝试了不同的Web服务结果格式,包括XML,但我无法使其中的任何一种工作。我可以验证(来自Fiddler2)Web服务正在被调用并返回数据,我的网格正在呈现我所说的列,但它不会显示数据。我不明白我在这里缺少什么,以及我是否需要修改Web服务结果,或者以不同方式指定架构,还是其他什么?
我的Javascript看起来像这样......(在尝试了很多不同的东西之后,这是我现在所拥有的)
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="../Content/kendo/2012.3.1114/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="../Content/kendo/2012.3.1114/kendo.default.min.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="../Scripts/kendo.all.min.js" type="text/javascript"></script>
</head>
<body>
<div id="grid" style="height: 400px; width: 900px;">
</div>
<script type="text/javascript">
var myWebServiceUrl = 'wMDTData.asmx';
var myGridData = new kendo.data.DataSource({
transport: {
read: {
url: myWebServiceUrl + '/Read',
dataType: "json",
type: "post",
contentType: "application/json; charset=utf-8"
}
},
schema: {
data: function (response) { return response.d; },
model: {
id: "ID",
fields: {
ID: { type: "string" },
ITEM_NAME: { type: "string" },
FUNCTION_NM: { type: "string" }
}
}
}
});
myGridData.read();
var myKendoGridOptions = {
dataSource: {
data: myGridData
}, //end of dataSource: object
columns: [{
width: 90,
field: "ID",
title: "ID"
}, {
width: 90,
field: "ITEM_NAME",
title: "Item Name"
}, {
width: 100,
field: "FUNCTION_NM",
title: "Function Name"
}] //end of columns: array
};
$(document).ready(
function () { $("#grid").kendoGrid(myKendoGridOptions); }
);
</script>
</body>
</html>
编辑:我修复了我的Web服务响应,它现在是一个JSON字符串,但事情仍然无法正常工作。我的网络服务以此回复......
{ "d":
{ "__type": "System.Data.DataTable", "columns": [
{ "name": "ID", "dataType": "Object", "defaultValue": null, "readOnly": false, "isKey": false },
{ "name": "ITEM_NAME", "dataType": "String", "defaultValue": null, "readOnly": false, "isKey": false },
{ "name": "FUNCTION_NM", "dataType": "String", "defaultValue": null, "readOnly": false, "isKey": false }
],
"rows": [
{ "ID": 1, "ITEM_NAME": "VR data to Close Package", "FUNCTION_NM": "CLOSE_PACKAGE_MAP_TO_BC" },
{ "ID": 2, "ITEM_NAME": "Currency Conversion", "FUNCTION_NM": "WV_CURRENCY_CONVERSION" },
{ "ID": 3, "ITEM_NAME": "GL Coding (wMDT Mapping)", "FUNCTION_NM": "GL_MAPPING" }
]
}
}
我尝试了一些不同的方法来指定要查看的内容 - XPath(字符串/),尝试将ID列设置为&#34; ID&#34; - 它只是没有解析这个。我也可以让它返回邪恶的丑陋的XML,但网格也没有很好地与这个... ...
<?xml version="1.0" encoding="utf-8"?>
<DataTable>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table" msprop:BaseTable.0="WMDT_ACCESS">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" msprop:BaseColumn="ID" msprop:OraDbType="107" type="xs:decimal" minOccurs="0" />
<xs:element name="ITEM_NAME" msprop:BaseColumn="ITEM_NAME" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
<xs:element name="FUNCTION_NM" msprop:BaseColumn="FUNCTION_NM" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet>
<Table diffgr:id="Table1" msdata:rowOrder="0">
<ID>1</ID>
<ITEM_NAME>VR data to Close Package</ITEM_NAME>
<FUNCTION_NM>CLOSE_PACKAGE_MAP_TO_BC</FUNCTION_NM>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<ID>2</ID>
<ITEM_NAME>Currency Conversion</ITEM_NAME>
<FUNCTION_NM>WV_CURRENCY_CONVERSION</FUNCTION_NM>
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="2">
<ID>3</ID>
<ITEM_NAME>GL Coding (wMDT Mapping)</ITEM_NAME>
<FUNCTION_NM>GL_MAPPING</FUNCTION_NM>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataTable>
所以,如果这里有一个问题,我应该使用哪个结果,以及如何将结果正确绑定到网格?
很抱歉发布&#34;讨论&#34;键入问题,但我被阻止了#34;正常&#34;论坛问这个。
答案 0 :(得分:1)
这只是略有不同,但它确实有效。有人可以解释原因吗?我真的不喜欢“旋转它直到它工作”的货物编程方法!
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="../Content/kendo/2012.3.1114/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="../Content/kendo/2012.3.1114/kendo.default.min.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="../Scripts/kendo.all.min.js" type="text/javascript"></script>
</head>
<body>
<div id="grid" style="height: 400px; width: 900px;">
</div>
<script type="text/javascript">
var myWebServiceUrl = 'wMDTData.asmx';
var myGridData = new kendo.data.DataSource({
transport: {
read: {
url: myWebServiceUrl + "/Read",
dataType: "json",
type: "post",
contentType: "application/json; charset=utf-8"
}
},
schema: {
data: "d"
}
});
myGridData.read();
$("#grid").kendoGrid({ dataSource: myGridData });
</script>
</body>
</html>
Web服务结果仍然与之前相同,即JSON结果。有人可以解释一下这里可能会发生什么吗?我将把“选项”重新放回去,似乎这就是搞乱它的原因,因为它是我真正删除的唯一东西。