【问题标题】:Is there any way to read the dojo Objectstore and convert it as JS array object有没有办法读取dojo Objectstore并将其转换为JS数组对象
【发布时间】:2018-07-12 12:49:24
【问题描述】:

寻找一种方法将 DOJO 增强网格 ObjectStore 中的所有行作为 JS Array 对象读取。

OnRowClick,我需要将所有项目作为一个数组。下面是示例代码:

Layout、Id 是在其他方法中定义的。 Id 是第一个标头。

在下面的代码中,store是dataStore。

function constructEnhancedGrid(jsObject) {
require(
    ["dojo/store/Memory", "dojo/data/ObjectStore",
        "dojox/grid/EnhancedGrid",
        "dojox/grid/enhanced/plugins/Pagination", "dojo/domReady!"
    ],
    function(Memory, ObjectStore, EnhancedGrid, Pagination) {

        jsGlobalObject = jsObject;
        jsObject = JSON.parse(jsObject);

        var objectStoreMemory = new Memory({
            data: jsObject,
            idProperty: [tableheaders[0]]
        });

        dataStore = new ObjectStore({
            objectStore: objectStoreMemory
        });

        constructEnhancedGridlayout(tableheaders);

        if (typeof rtGrid === "undefined") {
            rtGrid = new EnhancedGrid({
                store: dataStore,
                structure: enhancedGridLayout,
                plugins: {
                    pagination: {
                        pageSizes: ["10", "25", "50", "100"],
                        description: true,
                        sizeSwitch: false,
                        pageStepper: true,
                        gotoButton: false,
                        maxPageStep: 5,
                        position: "top",
                        defaultPageSize: 20
                    }
                },

            }, "rtGrid");
            rtGrid.startup();
        } else {
            rtGrid.setStructure(enhancedGridLayout);
            rtGrid.setStore(dataStore);
            rtGrid.currentPage(1);
            rtGrid.render(dataStore);
            rtGrid.startup();
        }
        dojo.connect(rtGrid, "onRowClick", function(e) {
            dataStore.fetch({
                query: {},
                onComplete: function(items) {
                    var resArray;
                    dataStore.objectStore.get().then(function(result) {
                        resArray = result;
                    });
                }
            });
        });
    });
}

【问题讨论】:

    标签: javascript dojo dojox.grid.datagrid dojox.grid


    【解决方案1】:

    更新答案

    最初我假设您使用 JsonRest,但现在我看到您使用 Memory 对象来填充您的数据网格。内存实例具有属性data,其中包含一个数据数组。您可以直接在代码中访问它。

        grid.on("RowClick", function (e) {
    
                var data = this.store.objectStore.data;
    
            })
        });
    

    【讨论】:

    • grid.store.objectStore.get() 没有返回所有对象。
    • @AjayKumar,很抱歉造成混淆。 get() 返回承诺,您可以从中获取必要的数据。我会更新我的答案。
    • 实际上 get() 方法没有返回任何对象,这是上面代码的错误。 “无法获取未定义或空引用的属性'then'”但是 get(id) 给出了一个对象。如果我一次获得所有对象而不进行迭代,那就太好了。
    • @AjayKumar 你能在你的问题中添加一些代码吗?你如何创建你的网格以及你试图在哪里获得结果。
    • 感谢您的快速回复。我的意思是 this.store.objectStore.get() 总是返回“未定义”。
    猜你喜欢
    • 2021-05-17
    • 1970-01-01
    • 2022-11-20
    • 2017-07-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多