带有dojo datagrid的备用小部件

时间:2013-08-01 14:55:54

标签: dojo dojox.grid.datagrid

我正在尝试使用将继续加载的备用小部件,直到加载了dojo数据网格。 我试着这个。但是,待机小部件不会出现。它只是等待,并加载数据。

        require([
        "dojox/grid/DataGrid",
        "dojo/store/Memory",
        "dojo/data/ObjectStore",
        "dojo/request",
        "dojox/widget/Standby",
        "dijit/form/Button",
        "dojo/domReady!",
        ],
        function (DataGrid, Memory, ObjectStore, request, Standby, Button) {
            var standby = new Standby({ target: "grid" });
            document.body.appendChild(standby.domNode);
            standby.startup();
            standby.show();
            var grid, dataStore;
            request.get("MyFile.aspx", {
                handleAs: "json"
            }).then(function (data) {
                dataStore = new ObjectStore({ objectStore: new Memory({ data: data }) });
                grid = dijit.byId("grid");
                grid.setStore(dataStore, { id: "*" }, {});                    
                var struct = [
                    { name: "Field1", field: "Name", width: "50%" },
                    { name: "Field2", field: "Name2", width: "50%" }, ];
                grid.setStructure(struct);
                grid.startup();
                standby.hide();

1 个答案:

答案 0 :(得分:1)

我认为这只是电话顺序的一个问题。您必须首先初始化网格,然后初始化备用数据库,然后获取数据并将其设置在网格中,然后隐藏备用数据库。在你的情况下:

    require([
        "dojox/grid/DataGrid",
        "dojo/store/Memory",
        "dojo/data/ObjectStore",
        "dojo/request",
        "dojox/widget/Standby",
        "dijit/form/Button",
        "dojo/domReady!",
        ],
        function (DataGrid, Memory, ObjectStore, request, Standby, Button) {
            //Create the grid
            var grid = new DataGrid({
                query: { id : '*' },
                structure : [
                    { name: "Field1", field: "Name", width: "50%" },
                    { name: "Field2", field: "Name2", width: "50%" }
                ]
            }, 'grid');
            grid.startup();

            //Create the stand by
            var standby = new Standby({ target: "grid" });
            document.body.appendChild(standby.domNode);
            standby.startup();
            standby.show();

            //Fetch data
            var grid, dataStore;
            request.get("teste.php", {
                handleAs: "json"
            }).then(function (data) {
                var grid = dijit.byId('grid');

                //Create store and put in the grid
                dataStore = new ObjectStore({ objectStore: new Memory({ data: data }) });
                grid.setStore(dataStore, { id: "*" }, {});

                //Hide standby
                standby.hide();
            }, function(error) {
                console.log(error);
            });
        }
   );