Is it possible to use 1 query object bound to different controls with different results?

I suspect that I would have to have a query object per widget, which would be a challenge if I had to say have 20 text boxes. Given that the query is exactly the same except for a filter parameter changing. Given the following code snippet, I can confirm the behavior is all 3 text boxes binds to the same data.
Is there a better alternative that spinning up 20 query objects with the exact same query?

export default {
	txt1Bind : () => {
		return JSON.stringify(Query1.data[0],null,4);
	},
	
	txt2Bind : () => {
		return JSON.stringify(Query1.data[0],null,4);
	},
	
	txt3Bind : () => {
		return JSON.stringify(Query1.data[0],null,4);
	},
	
	button1_onClick : () => {
		Query1.run({genreName : "Thriller"});
	},
	
	button2_onClick : () => {
		Query1.run({genreName : "Comedy"});
	},
	
	button3_onClick : () => {
		Query1.run({genreName : "Action"});
	}	
}

the query:

{
  "find": "movies",
  "filter": { "genres.name": "{{this.params.genreName}}" },
  "sort": {
    "_id": 1
  },
  "limit": 10
}

@Elroy since the filter param is changing, there would need to be this code that sends the different parameter in one place or the other. So your implementation does seem correct

Hi Nikhil, yes the implementation works but does not serve well for additional controls. Eg 20 additional text boxes means 20 queries, is there a better way to do this?

@Elroy there would only be 1 query but you would need to write code that triggers it from each of the widgets that you click. So a single query but js written in 20 places.
I can’t think of a way to avoid this because even if you were doing this in code, you would achieve it this way am I right? Do you have a suggestion on how we can make this easier?

Apologies, the issue with the above implementation is that all 3 text boxes will change to the same value depending on what button you click. Ideally only the button. What i would like is to dynamically assign the query to the txt box. is that possible?

@Elroy oh! Now I get the problem. So what you can do is onSuccess of the query, you can store the response based on the textbox name and then read the value from the store so you can avoid needing multiple queries

1 Like