Dojo Javascript筛选选择后选择框为空

时间:2018-10-24 12:54:15

标签: javascript dojo

我在显示应在“ SelectType”框中显示的值时遇到问题。页面加载时,没有根据需要进行选择。下拉菜单将根据需要打开,并显示所需的值。 但是,如果您选择一个值,则它不会保留在框中,并且在调试器的输出中会出现“ Uncaught TypeError:无法读取未定义的'toLowerCase'属性”。 不幸的是,我对Dojo框架和Java还是很陌生,在解决方案上困扰了好几天。有人对我有想法或小费吗?随附代码:如果缺少某些内容,请告诉我。

预先感谢

            startup: function() {

            if(this.logger.isDebug()) {
                this.logger.debug("startup()");
            }

            try {
                this.borderContainer.startup();
            } catch(ex) {
                console.dir(ex);
            }

            this.selectUser.set('store', new JsonRestStore({
                    service:        RestService.create({ path: 'servicelog/users/'}),
                    idAttribute:    "userId"
                })
            );
            this.selectUser.set('searchAttr', "userId");

            this.selectType.set('store', new JsonRestStore({
                    service:        RestService.create({ path: 'servicelog/methods/'}),
                    idAttribute:    "nr"
                })
            );          

            this.selectType.set('labelFunc', lang.hitch(this, function(item, store) { 
                return this.resources.getString('servicelog.type.' + item.nr, store);
            }));

            this.selectionFetch = {};

            if (this.restore) {
                this.setOptions(this.restore);
            } else {
                this.selectType.set('item', { nr : 0 });
                this.selectFrom.set('value', new Date());
            }

            this.store = new JsonRestStore({
                service: RestService.create({
                            path: 'servicelog/find/'
                        }),
                idAttributes: ["logId"],
                fetchProperties : this.selectionFetch
            });

            this.grid.set('structure', this.prepareColumnStructure());
            this.grid.set('formatterScope', this);
            this.grid.set('store', this.store);

            /* Listener */
            on(this.grid, "RowDblClick", lang.hitch(this, this.onDblClick));
            on(this.buttonReload, "Click", lang.hitch(this, this.refresh));
            on(this.buttonExport, "Click", lang.hitch(this, this.exportData));

            this.onLoad();
            this.setSearchAttributes();

            if(this.logger.isDebug()) {
                this.logger.debug("startup(...)  [grid: ", this.grid, ", store: ", this.store, "]");
            }
        },

        setSearchAttributes : function() {
            this.selectionFetch = {};

            //SELECT TYPE
            if (this.selectType.getValue() > 0) {
                this.selectionFetch.selectType = this.selectType.getValue();
            } else {
                this.selectionFetch.selectType = 0;
            }

            //ERR ONLY
            if (this.selectErrorOnly.checked) {
                this.selectionFetch.errorOnly = true;
            }

            //KEY
            if (this.selectKeyword.getValue() != null) {
                this.selectionFetch.keyword = this.selectKeyword.getValue();
            }

            //FROM
            if (this.selectFrom.getValue() != null) {
                this.selectionFetch.from = stamp.toISOString(this.selectFrom.getValue());
            }

            //TILL
            if (this.selectTill.getValue() != null) {
                this.selectionFetch.till = stamp.toISOString(this.selectTill.getValue());
            }

            //USER
            if (this.selectUser.getValue() != null && this.selectUser.getValue() != "") {
                this.selectionFetch.user = this.selectUser.getValue();
            }

            //TYPE
//          if (this.selectType.getValue() != null && this.selectType.getValue() != "") {
//              this.selectionFetch.type = this.selectType.getValue();
//          }
//          
            this.store.fetchProperties = this.selectionFetch;

            //this.refresh();
        },

        getWindowTitle: function() {
            return this.resources.getString('servicelog.title');
        },

        exportData : function() {

            var queryStr = dojo.objectToQuery(this.selectionFetch);
            var url = "servicelog/find/export/?" + queryStr;

            FileDownloader.download(url, "Export", "GET");
        },

        /**
         * This method is called by the parent widget to get a array of functional control elements
         */
        getMenuItems: function() {
            if(this.logger.isDebug()) {
                this.logger.debug("getMenuItems()");
            }

            return [this.buttonReload]; //, this.buttonExport];
        },

        /**
         * This Method returns the params to reinit this widget with the actuall settings 
         */
        getOptions: function(){
            return { restore : this.selectionFetch };
        },

        setOptions: function(options) {
            if(this.logger.isDebug()) {
                this.logger.debug("setOptions(options: ", options ,")");
            }

            if (!options || options == null) {
                return false;
            }

            this.selectionFetch = options;

            console.debug("setOptions", this.selectionFetch);

            //SELECT TYPE
            if (this.selectionFetch.selectType) {
                console.debug("set selectType to: ", this.selectionFetch.selectType);
                this.selectType.setValue('item', { nr : this.selectionFetch.selectType });
            } else {
                console.debug("set selectType to all");
                this.selectType.setValue('item', { nr : 0 });
            }

            //ERR ONLY
            if (this.selectionFetch.errorOnly && this.selectionFetch.errorOnly == true) {
                this.selectErrorOnly.set('checked', true);
            }

            //KEY
            if (this.selectionFetch.keyword) {
                this.selectKeyword.setValue(this.selectionFetch.keyword);
            }

            //FROM
            if (this.selectionFetch.from) {
                this.selectFrom.setValue(stamp.fromISOString(this.selectionFetch.from));
            }

            //TILL
            if (this.selectionFetch.till) {
                this.selectTill.setValue(stamp.fromISOString(this.selectionFetch.till));
            }

            //USER
            if (this.selectionFetch.user) {
                this.selectUser.setValue(this.selectionFetch.user);
            }

            return true;
        },

        openDetailWidget: function(args, newWindow) {
            if(this.logger.isDebug()) {
                this.logger.debug('openDetailWidget: function(args,newWindow): ', args ,',', newWindow);
            }

            this.openContentWidget(ServiceLogDetailWidget, args, newWindow);
        },

        /**
         * This method converts the backend-side view object array to a valid grid structure
         */
        prepareColumnStructure: function() {

            if(this.logger.isDebug()) {
                this.logger.debug("prepareColumnStructure(datafieldDataList: ", datafieldDataList ,")");
            }

            /* Parts of struture: scroll & no scroll */
            var cells = {scroll: true, cells: new Array(6) }; 

            /* the first column */
            cells.cells[0] = {
                    field        : 'logId',
                    name         : this.resources.getString('servicelog.grid.id'),  
                    width        : '60px',
                    headerStyles : 'height: '+ this.HEADER_HEIGHT +'px; white-space: normal;',
                    formatter    : Formatter.stringFormat
            };

            cells.cells[1] = {
                    field        : 'requestAt',
                    name         : this.resources.getString('servicelog.grid.request_at'),
                    width        : '120px',
                    headerStyles : 'height: '+ this.HEADER_HEIGHT +'px; white-space: normal;',
                    formatter    : Formatter.dateTimeFormat
            };

            cells.cells[2] = {
                    field        : 'serviceType',
                    name         : this.resources.getString('servicelog.grid.type'),
                    width        : '120px',
                    headerStyles : 'height: '+ this.HEADER_HEIGHT +'px; white-space: normal;',
                    formatter    : Formatter.stringFormat,
                    get          : lang.hitch(this, function(rowId, obj) {
                        if(obj && obj != null){
                            return this.resources.getString('servicelog.type.' + obj.serviceType);
                        }
                    })
            };

            cells.cells[3] = {
                    field        : 'requestUser',
                    name         : this.resources.getString('servicelog.grid.user'),
                    width        : '120px',
                    headerStyles : 'height: '+ this.HEADER_HEIGHT +'px; white-space: normal;',
                    formatter    : Formatter.stringFormat
            };

            cells.cells[4] = {
                    field        : 'responseAt',
                    name         : this.resources.getString('servicelog.grid.worktime'),
                    width        : '120px',
                    headerStyles : 'height: '+ this.HEADER_HEIGHT +'px; white-space: normal;',
                    get          : lang.hitch(this, function(rowId, obj) {
                        if(obj && obj != null){

                            var from = stamp.fromISOString(obj.requestAt);
                            var till = stamp.fromISOString(obj.responseAt);

                            if ((till - from) < 0) return '-'; 

                            return number.round((till - from) / 1000) + ' sec';
                        }
                    })
            };

            cells.cells[5] = {
                    field        : 'errorCode',
                    name         : this.resources.getString('servicelog.grid.error'),
                    width        : '150px',
                    headerStyles : 'height: '+ this.HEADER_HEIGHT +'px; white-space: normal;',
                    formatter    : Formatter.stringFormat,
                    get          : lang.hitch(this, function(rowId, obj) {
                        if(obj && obj != null){
                            return this.resources.getString('servicelog.error.' + obj.errorCode);
                        }
                    })
            };

            return [ cells ];
        },

0 个答案:

没有答案