0

我无法将 selectionMode 保持为“single”或“extended”。当我使用 dojo Memory/ObjectStore 作为存储时,只会发生多行选择。

    require([
    "dojo/_base/declare",
    "dojo/request",
    "dojo/data/ObjectStore",
    "dojo/store/Memory",
    "dgrid/OnDemandGrid",
    "dgrid/Keyboard",
    "dgrid/Selection",
    "dojo/DeferredList",
    "dojo/domReady!"
    ],
    function (declare, request, ObjectStore, Memory, OnDemandGrid, Keyboard, Selection, DeferredList) {

        var ddstore;


        claimDef = dojo.xhrGet({
            url: "pageToGetData.aspx",
            handleAs: "json",
            load: function (res) {
                // Resolve when content is received 
                ddstore = new Memory({ data: res });

            }
        });


        var defs = new dojo.DeferredList([claimDef]);
        defs.then(function (results) {
            // Create a new constructor by mixing in the components
            var CustomGrid = declare([OnDemandGrid, Keyboard, Selection]);

            claimAccountsGrid = new CustomGrid({
                columns: [
                { label: "Label1", field: "Field1" },
                { label: "Label2", field: "Field2" },
                { label: "Label3", field: "Field3" },
             ]

            }, "claimAccountsGrid");
            claimAccountsGrid.setStore(ddstore);


        });
    });

但是,当我对从该页面获得的相同数据进行硬编码时,我可以将默认 selectionMode 设置为“扩展”。(这种方式):

    require([
    "dojo/_base/declare",
    "dojo/request",
    "dojo/data/ObjectStore",
    "dojo/store/Memory",
    "dgrid/OnDemandGrid",
    "dgrid/Keyboard",
    "dgrid/Selection",
    "dojo/DeferredList",
    "dojo/domReady!"
    ],
    function (declare, request, ObjectStore, Memory, OnDemandGrid, Keyboard, Selection, DeferredList) {
        pageNo = 1;
        var ddstore;


        claimDef = dojo.xhrGet({
            url: "pageToGetData.aspx",
            handleAs: "json",
            load: function (res) {
                // Resolve when content is received 
                ddstore = //new Memory({ data: res });

                [
                { "Field1": "value1", "Field2": null, "Field3": "1" },
                { "Field1": "value2", "Field2": null, "Field3": "1"}
                ];
            }
        });


        var defs = new dojo.DeferredList([claimDef]);
        defs.then(function (results) {
            // Create a new constructor by mixing in the components
            var CustomGrid = declare([OnDemandGrid, Keyboard, Selection]);

            claimAccountsGrid = new CustomGrid({
                columns: [
                { label: "Label1", field: "Field1" },
                { label: "Label2", field: "Field2" },
                { label: "Label3", field: "Field3" },
             ]
            }, "claimAccountsGrid");
            //claimAccountsGrid.setStore(ddstore);
            claimAccountsGrid.renderArray(ddstore);

        });
    }); 
4

1 回答 1

2

由于您没有显示实际数据,我无法 100% 确定,但如果您未能正确确保您的商品具有唯一标识符(或者,如果标识符字段不是id,则您忘记了在内存存储上设置idProperty以通知它要查看的字段)。

另请参阅https://github.com/SitePen/dgrid/issues/61

于 2014-11-17T02:23:20.257 回答