Michael Droll
Posts: 0
Joined: Wed Mar 04, 2015 5:05 am

Combine queries from multiple Collections in list

I shared the app with support if that will help.
Steps to test:

1: login with user: test password: 123
2: after login the page that loads will have a list with dummy data i put in for you.
will be 4 list items that are populated from the list service "GetProperties" from the "Properties" collection.

there is a grid in each list item, with the following:
Pros: ..... Cons: .....

each list item will have a different count of "Pros" equal to the "test address" number. ex: "test address 1" should have 1 Pro, "test address 2" should have 2 Pros, "test address 3" should have 3 Pros
So you will know what to look for.

if you open the dev console in the browser you will see all the logs for each "test address" and in the network tab see the services being executed.

the "...." labels are not showing the count. in the log it says code "there are [object Object]PRO comments for property id: 56dbc29be4b07fb4XXXXXXXX"/code

I also don't under stand why it says "[object Object]" it should just be the count of the query.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Combine queries from multiple Collections in list

1) Please remove request parameter "count" from your service. If it exists in the request - service returns only amount of items

2) If you use JS on the mapping like:
presuccessFunction(value);/pre
please add an element as a second parameter of that function, e.g.:
presuccessFunction(value, element);/pre
3) If these items don't help you - please write a name of your app

Michael Droll
Posts: 0
Joined: Wed Mar 04, 2015 5:05 am

Combine queries from multiple Collections in list

1) A: But the count is what I need. If I remove it then the service will return all of the comments for that property. Unless there is a way in JS to count the number of returned comments for each property. Is that what I need to do?

2) A: sorry but i don't understand what this is or how it works.

3) A: The name of the app is "Home Score".

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Combine queries from multiple Collections in list

You can count response items with JS below on the service success event:
prevar count = data.length;/pre

Michael Droll
Posts: 0
Joined: Wed Mar 04, 2015 5:05 am

Combine queries from multiple Collections in list

OK I have it all working as I hoped it would!!!

here is the final JavaScript I had to run on the mapping of the response.
code
function successFunction(data) {

Code: Select all

 if (data.length > 0) { 

     console.log(data); 
     var count = data.length; 
     console.log('there are ' + count + ' PRO comments for property id: ' + value); 

     $(element).closest("li").find("[name=ProsLabel]").text(count); 

     //Apperyio('ProsLabel').text(count); 

 } 
 var Label = $(element).closest("li").find("[name=ProsLabel]").text().length; 
 var length = Label.length; 
 console.log('length is "' + Label); 
 if (Label > 2) { 
     $(element).closest("li").find("[name=ProsLabel]").text(0); 
 } 

}

ProsCount.execute({
data: {
"where": '{"PropID":"' + value + '","ProCon":"pro"}'
},
success: function(data) {

Code: Select all

     successFunction(data); 
 } 

});

return value;
/code

and here is the end result!
Image

Thank you so much for all the help and patience it took for me to get this to work! I hope my users will enjoy the new feature in the app.

Return to “Issues”