Dojo Javascript变量范围 [英] Dojo Javascript variable scope

查看:126
本文介绍了Dojo Javascript变量范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 dgrid ,我正在尝试外部设置dataStore。当页面加载时,我调用 aliasTicket.load()来创建网格。在网格加载的时候,数据源为null。当执行查询时,将设置 setAliasSource(aliasData);

I am using dgrid and i am attempting to set the dataStore externally. When the page loads i call aliasTicket.load() to create the grid. At the time the grid is loading the datasource is null. When a query is executed the setAliasSource(aliasData); is set.

没有错误,但是网格是还是空的aliasStore正在使用数据进行更新,即使在刷新网格之后,它还没有反映在网格上。查询后如何获取网格中反映的数据?

There are no errors however the grid is still empty. The aliasStore is being updated with data however it isn't being reflected on the grid even after the grid is refreshed. How can i get the data reflected in the grid after the query?

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();


推荐答案

您正在将this.Store设置为一个对象数组,而不是一个真正的'dojo存储'对象。按照您的代码,我看不到您实际使用this.Store的位置。在网格代码中,我看到一个名为Store的局部变量。

You are setting 'this.Store' to an object array, not a real 'dojo store' object. Following your code I can not see where you actually use 'this.Store'. Inside the grid code I do see a local variable named 'Store'.

所以我不知道我是否遵循你的代码示例,但是你应该'设置网格的存储,然后刷新它。这样的东西。

So I'm not sure if I'm following your code example here but, you should 'set' the store of the grid and then refresh it. Something like this.

 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();

    },

这篇关于Dojo Javascript变量范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆