0

我不明白这里发生了什么,但我认为这只是没有正确理解架构。我尝试了许多不同的选项、表达模式的方式,并且尝试了不同的 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(string/),尝试将 ID 列设置为“ID” - 它只是没有解析这个。我也可以让它返回邪恶丑陋的 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>

所以,如果这里有问题,我应该使用哪个结果,以及如何让该结果正确绑定到网格?

很抱歉发布“讨论”类型的问题,但我被“正常”论坛阻止问这个问题。

4

1 回答 1

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 结果。有人可以解释这里可能发生的事情吗?我将把“选项”放回去,这似乎是把它搞砸了,因为它是我唯一真正删除的东西。

于 2013-03-27T20:59:53.073 回答