小编典典

Dojo Javascript变量范围

json

我正在使用dgrid,并且尝试在外部设置dataStore。当页面加载时,我打电话aliasTicket.load()来创建网格。在网格加载时,datasourcenull为null。执行查询时,setAliasSource(aliasData);将设置。

没有错误,但是网格仍然是空的。正在使用数据更新aliasStore,但是即使刷新了网格也没有将其反映在网格上。查询后如何获取反映在网格中的数据?

Javascript对象

   var aliasTicket = (function (){

    var aliasData = [];

    require([ "dojo/store/Observable", "dojo/store/Memory"]);   
    var aliasStore = new dojo.store.Observable(new dojo.store.Memory({
        data: aliasData,
        idProperty: "id"
      }));

    return{

        load:function(){

            require([
                     ........

                   ], function(declare, Memory, OnDemandGrid, ColumnSet, Selection,
                     selector, Keyboard, DijitRegistry, editor, ColumnHider,
                     registry, Observable,lang) {

                aliasData = this.aliasData;

                var Store = this.aliasStore = new dojo.store.Observable(new dojo.store.Memory({
                    data: aliasData,
                    idProperty: "id"
                  }));

                console.log(Store);

                var CustomAliasNameGrid = declare([OnDemandGrid, selector, Selection, Keyboard, editor, DijitRegistry, ColumnHider]);

                  var aliasNameGrid = new CustomAliasNameGrid({
                    store: Store,
                    columns: {
                      id: {
                        label: "Id",
                        field: "id",
                        hidden: true,
                        autoSizeColumn: true
                      },

                      employeeTicketId: {
                        label: "Employee Ticket Id",
                        field: "employeeTicketId",
                        hidden: true,
                        autoSizeColumn: true
                      },

                      chkBox: selector({}),


                      aliasName: {
                        label: "Alias Names",
                        field: "aliasTicketName",
                        autoSizeColumn: true,
                        formatter: function(str) {
                          return str.replace(/\w\S*/g, function(txt) {
                            return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
                          });
                        }
                      }

                    },
                    selectionMode: "none",
                    loadingMessage: "Loading data...",
                    noDataMessage: "No results found....",
                    allowSelectAll: true
                  }, "aliasNameGrid");



                aliasNameGrid.refresh()

            });

        },

        setAliasSource: function (data){
            console.log(data);
            this.aliasSource = data;

        },

        setAliasData: function (data){
            this.aliasData = data;              
        },

        getAliasSource: function (){

            return this.aliasSource;
        }

    };

})();

设置数据存储数据

aliasData = [{.....},
             {.....},
             {......];


            require(["dijit/dijit"]);
            aliasTicket.setAliasSource(aliasData);              
            dijit.byId('aliasNameGrid').refresh();

阅读 190

收藏
2020-07-27

共1个答案

小编典典

您正在将“ this.Store”设置为对象数组,而不是真正的“ dojo store”对象。按照您的代码,我看不到您实际在哪里使用“
this.Store”。在网格代码内部,我确实看到了一个名为“ Store”的局部变量。

因此,我不确定是否在这里遵循您的代码示例,但是,您应该“设置”网格的存储,然后刷新它。这样的事情。

 setAliasSource: function (data){
        console.log(data);
        this.Store = data;
        dijit.byId('aliasNameGrid').set("store",new dojo.store.Observable(new dojo.store.Memory({ data: data,idProperty: "id"}));
        dijit.byId('aliasNameGrid').refresh();

    },
2020-07-27