【问题标题】:jsGrid with multple data sources具有多个数据源的 jqGrid
【发布时间】:2021-04-14 15:04:04
【问题描述】:

我有一个 jsGrid,我想在其中显示具有多个外键的数据库表中的数据,因此网格数据的某些字段是引用不同来源的外键:为此,我编写了以下内容

$(function() {
    $.when(
      $.ajax({type: "GET", url: "/datasource1/"}),
      $.ajax({type: "GET", url: "/datasource2/"})
    ).then(
      (data1, data2) => {
        $("#jsGrid").jsGrid({
            // irrelevant options for the grid
            controller: {
                loadData: function(filter) {
                    return $.ajax({
                        type: "GET",
                        url: "/griddata/",
                        data: filter
                    });
                },
                insertItem: function(item) {...},
                updateItem: function(item) {...},
                deleteItem: function(item) {...}
            },
            fields: [
                { name: "foreign1", title: "FK1", type: "select", width: 100, items: data1, valueField: "id", textField: "value" },
                { name: "foreign2", title: "FK2", type: "select", width: 100, items: data2, valueField: "id", textField: "value" },
                { type: "control" }
            ]
        });
    });
});

据我了解,when 应该等待两个 ajax 调用来检索它们的数据,然后渲染网格。不幸的是,我可以看到网格中的行,但没有这些字段的值,既不是外键,也不是 data1data2 数组上的相应值(两者都被正确检索)。

我错过了什么吗?

【问题讨论】:

    标签: jquery jsgrid


    【解决方案1】:

    我遇到了类似的问题,对我来说,解决方案是 loadData 函数中的数据只需要返回“valueField”,而不是整个对象。

    在这种情况下 loadData 应该返回这个:

    [{foreign1:1,foreign2:1},...]
    

    不是这个:

    [{foreign1:{id:1, value:"one"},foreign2:{id:1, value:"one"},...]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      相关资源
      最近更新 更多