javascript - YUI数据表错误

标签 javascript datatable yui

我正在尝试组合一个使用 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 });

}

欢迎并感谢任何帮助。提前致谢。

最佳答案

我相信可重写的 doBeforeParseData 方法应该返回 oFullResponse 对象...

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

..但可能不仅仅如此。

关于javascript - YUI数据表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2327035/

相关文章:

javascript - jquery如何让一个元素在动画结束后回到初始位置

asp.net - 如何覆盖外部 css?

javascript - 图像 URL 在尝试用作背景样式时不起作用

Javascript - 返回方括号之间的字符串

javascript - 折叠/展开时动画字体 Awesome Chevron 图标旋转

javascript - 获取删除数据表中行的问题

c# - 试图从数据库中获取数据并将其加载到数据表中出现异常

c# - SQL 服务器 : pass datatable to stored procedure with a null value

YUI3相当于getQueryStringParameter用于获取查询字符串参数

javascript - 在 Prototype 中使用自己的 AJAX 请求回调方法