【问题标题】:Grid: Remote Data Source网格:远程数据源
【发布时间】:2014-09-09 16:49:41
【问题描述】:

我正在尝试使用远程数据源实现 W2UI 网格,我最初使用返回结果的 aspx 页面使其工作。

我已经迁移到 API,因此可以提取和更新数据

我遇到的问题或问题是经常需要破解和削减我返回的数据: “{\"status\":\"success\",\"total\":\"X\",\"records\":”....

这会导致其他组件出现问题,而不是仅仅返回 IEnumerable,因为我现在需要复制逻辑等

我希望我遗漏了一些东西,而不是 W2UI 中总是首先需要状态/总结果的缺陷。

【问题讨论】:

    标签: jquery asp.net webforms w2ui


    【解决方案1】:

    它似乎确实需要total 和status 才能发挥作用。使用 C#,我创建了一个或多或少自动处理此问题的类:

    // a few using statements that are needed
    using NewtonSoft.Json;
    using System.Data;
    using System.Data.SqlClient; 
    
    // the class we will need to Serialize
    public class w2return
    {
        public string status = "success";
        public int total = 0;
        public DataTable records;
    }
    

    现在在您的网络服务功能中,执行以下操作:

    w2return x = new w2return();
    // write some code to return a DataTable
    x.records = SomeCodeThatReturnsDataTable();
    x.total = x.records.Rows.count();
    
    return JsonConvert.SerializeObject(x); // this assumes your function returns a string
    

    由于序列化过程将整个过程包装在一个名为“d”的成员变量中,因此您需要在客户端使用 w2ui 的“parse”回调(假设您使用的是 jQuery)将其解析回:

    parser: function (responseText) { return $.parseJSON($.parseJSON(responseText).d); }
    

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多