Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jgunders
Contributor II
Contributor II

General function to set selection state of another app for mashups

Trying to write a general function to set the selection state in another app when writing mashups.

	var stateListener = function(theApp) {	 	
	theApp.clearAll();
    	var selFields = this.selections;
		
		if (selFields!=null){
		$.each(selFields, function(key, value) {
			var valArray=[];
			$.each(value.selectedValues, function(key,value){
				valArray.push(value.qName);
			})
			theApp.field(value.fieldName).selectValues(valArray, true, true);
		});
		}		
  	};

 

So trying to use it like this:

var selState = app.selectionState( );    //get state of app

selState.OnData.bind( stateListener, app1 );    //bind to function with argument of app1 to set it's state

But it's not calling the listener. 

Ideas appreciated!

 

1 Solution

Accepted Solutions
jgunders
Contributor II
Contributor II
Author

Found a work-around but not that happy with it.  Instead of an argument I set a global scope var to the application:

	var theApp;

	function stateListener() {	 	
		theApp.clearAll();
		var selFields = this.selections;

		if (selFields!=null){
		$.each(selFields, function(key, value) {
			var valArray=[];
			$.each(value.selectedValues, function(key,value){
				valArray.push(value.qName);
			})
			theApp.field(value.fieldName).selectValues(valArray, true, true);
		});
		}		
	}

and use the function like:

var selState = app.selectionState( ); //get state of app
theApp = app1; //set global to app1
selState.OnData.bind( stateListener ); //bind to function

View solution in original post

1 Reply
jgunders
Contributor II
Contributor II
Author

Found a work-around but not that happy with it.  Instead of an argument I set a global scope var to the application:

	var theApp;

	function stateListener() {	 	
		theApp.clearAll();
		var selFields = this.selections;

		if (selFields!=null){
		$.each(selFields, function(key, value) {
			var valArray=[];
			$.each(value.selectedValues, function(key,value){
				valArray.push(value.qName);
			})
			theApp.field(value.fieldName).selectValues(valArray, true, true);
		});
		}		
	}

and use the function like:

var selState = app.selectionState( ); //get state of app
theApp = app1; //set global to app1
selState.OnData.bind( stateListener ); //bind to function