0

我正在尝试使用将继续加载的备用小部件,直到加载 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();
4

1 回答 1

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);
            });
        }
   );
于 2013-08-01T21:43:18.287 回答