Page 1 of 2

Filter data that is in an array

Posted: Mon Jul 25, 2016 9:00 am
by Deon

Hi
I have a mapping that displays data located in an array. I only want certain data from the array.
How do I filter on an array? I have used the same filtering I use for normal fields but this has no effect. All data is returned.

Thank you.


Filter data that is in an array

Posted: Tue Jul 26, 2016 5:04 am
by Yurii Orishchuk

Hi Deon,

You can try following:

1 create other storage with such array model.

2 copy first array storage to second array storage(using filter - so you will copy only needed elements).

3 make mapping from second array to the page.

Regards.


Filter data that is in an array

Posted: Tue Jul 26, 2016 7:45 am
by Deon

Hi Yuri
How do you copy the data based on a filter?
Do you have any docs on this?


Filter data that is in an array

Posted: Tue Jul 26, 2016 8:03 am
by Deon

This is how the data is stored in the array...
As you can see, I have fieldName and fieldValue.
So data in fieldName = FirstName (the actual name of the field) then the fieldValue would be "Peter" which is the value of the FrstName.

SO what I need to achieve for example is retrieve only FirstName and not Lastname from fieldName as well as the FirstName's associated value which is located in fieldValue.
Image


Filter data that is in an array

Posted: Fri Jul 29, 2016 12:18 pm
by Deon

Any update please?


Filter data that is in an array

Posted: Tue Aug 02, 2016 7:52 am
by Deon

Again. Can anyone help with this please??


Filter data that is in an array

Posted: Tue Aug 02, 2016 11:59 am
by Deon

How dow I do this? There are no instructions on copying arrays from one storage to another! PLEASE people. This is urgent!


Filter data that is in an array

Posted: Tue Aug 02, 2016 10:42 pm
by Andrew Peacock

Hi Deon,
This sounds like a job for underscore JS:

var filterArray = _.filter(originalArray, function(item) { return item.FieldName == 'FirstName'; });

That should do it. Hope it helps,
Andy


Filter data that is in an array

Posted: Wed Aug 03, 2016 5:00 am
by Yurii Orishchuk

Hi Deon,

Here is a code to get items from a storage and copy it to another storage with some condition.

pre

//var originalArray = [{id: 1}, {id: 2}, {id: 3}];

//Getting original Array from the storage.
var originalArray = Apperyio.storage.originalArray.get();

var resultArray = [];

for(var i = 0; i < originalArray&#46;length; i++){

Code: Select all

 &#47;&#47;Condition how you want to filter items&#46; Only items that satisfies this condition - will be added to result array&#46; 
 if(originalArray[i]&#46;id  1) 
     resultArray&#46;push(originalArray[i]); 

}

&#47;&#47;Store result in a storage&#46;
Apperyio&#46;storage&#46;resultArray&#46;set(resultArray);

/pre

Regards.


Filter data that is in an array

Posted: Thu Aug 11, 2016 3:34 am
by Deon

Hi Andy/Yurii

Thank you both for your answers.

Yurii, I implemented your solution. It works 100%

Thank you very much.