Javascript YUI数据表错误

Javascript YUI数据表错误,javascript,datatable,yui,Javascript,Datatable,Yui,我正在尝试组装一个使用YUI的DataTable组件的应用程序,但是我得到了“数据错误”消息。数据源配置为从ASP.NET web方法获取记录。记录被成功地返回到客户端(我用IE的调试器检查了它)。我的代码如下所示: YAHOO.example.Basic = function() { var dsWS_Restaurants = new YAHOO.util.DataSource("/DemoWebSite/RestaurantsWebService.asmx/GetL

我正在尝试组装一个使用YUI的DataTable组件的应用程序,但是我得到了“数据错误”消息。数据源配置为从ASP.NET web方法获取记录。记录被成功地返回到客户端(我用IE的调试器检查了它)。我的代码如下所示:

YAHOO.example.Basic = function() {
            var dsWS_Restaurants = new YAHOO.util.DataSource("/DemoWebSite/RestaurantsWebService.asmx/GetList", { connMethodPost: true });

            dsWS_Restaurants.connMgr = YAHOO.util.Connect;
            dsWS_Restaurants.connMgr.initHeader('Content-Type', 'application/json; charset=utf-8', true);
            dsWS_Restaurants.responseType = YAHOO.util.DataSource.TYPE_JSON;

            dsWS_Restaurants.doBeforeParseData =
                function(oRequest, oFullResponse, oCallback) {
                    // checked here if oFullResponse contains the desired results and it does.
                }

            dsWS_Restaurants.responseSchema =
            {
                resultsList: 'd.records',
                fields: ["id", "name"]
            };

            var dsWS_Restaurants_ColumnDefs = [
                { key: "id", sortable: true, resizeable: true },
                { key: "name", sortable: true, resizeable: true }
                ];

            var dsWS_Restaurants_DataTable =
                new YAHOO.widget.DataTable("basic4", dsWS_Restaurants_ColumnDefs, dsWS_Restaurants, { caption: "dsWS_Restaurants" });

            return {
                oDS: dsWS_Restaurants,
                oDT: dsWS_Restaurants_DataTable
            };
        } ();

Web方法如下所示:

public Object GetList() {
    var restaurants =
        new []{
            new
            {
                id="1",
                name="Popeyes spinach"
            },
            new
            {
                id="2",
                name="Big pappas cottage"
            }
        };

    return restaurants.Select (x => new { id = x.id, name = x.name });
}


欢迎并感谢您的帮助。提前感谢。

我认为可重写的DobeForApparseData方法应该返回oFullResponse对象

        dsWS_Restaurants.doBeforeParseData =
            function(oRequest, oFullResponse, oCallback) {
                // checked here if oFullResponse contains the desired results and it does.
                 return oFullResponse;
            }

。。但可能不止这些。

我发现了错误的原因。在数据源的responseSchema中,resultList被定义为“d.records”,但我没有web方法返回的“records”字段。我用“d”替换了“d.records”,样本成功了。我的错误是,我从使用“records”字段的示例应用程序中借用了代码


愉快的编码。

一个或一个复制链接怎么样?也值得发布在IE调试器中记录的JSON。