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.
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.
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.
Hi Yuri
How do you copy the data based on a filter?
Do you have any docs on this?
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.
Any update please?
Again. Can anyone help with this please??
How dow I do this? There are no instructions on copying arrays from one storage to another! PLEASE people. This is urgent!
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
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.length; i++){
Code: Select all
//Condition how you want to filter items. Only items that satisfies this condition - will be added to result array.
if(originalArray[i].id 1)
resultArray.push(originalArray[i]);
}
//Store result in a storage.
Apperyio.storage.resultArray.set(resultArray);
/pre
Regards.
Hi Andy/Yurii
Thank you both for your answers.
Yurii, I implemented your solution. It works 100%
Thank you very much.