Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Filter data that is in an array

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.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

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

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

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

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

Any update please?

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

Again. Can anyone help with this please??

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

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

Andrew Peacock
Posts: 0
Joined: Thu Jan 09, 2014 10:03 pm

Filter data that is in an array

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Filter data that is in an array

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.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Filter data that is in an array

Hi Andy/Yurii

Thank you both for your answers.

Yurii, I implemented your solution. It works 100%

Thank you very much.

Return to “Issues”