Definitely Not.
The Ionic directive called filter
handles filtering logic even before entering the for loop
. Therefore, you have the option to perform your own filtering prior to rendering.
You can achieve this by utilizing ES6 filter function or other utility functions.
For example, let's say we want to display only odd numbers:
render() {
return(
<View>
{[1, 2, 3, 4, 5]
.filter(value => value % 2 === 1)
.map(value => (<Text key={value}>{value}</Text>))}
</View>
);
}
To take it a step further, you can create a component with a filter property and implement custom logic. This way, you can use it similar to how Ionic works.
For instance:
class FilterNumbers extends Component {
static propTypes = {
numbers: PropTypes.array.isRequired,
filter: PropTypes.func,
};
static defaultProps = {
filter: null,
numbers: [],
};
render() {
var filteredNumbers = this.props.numbers;
if (this.props.filter) {
filteredNumbers = this.props.numbers.filter(this.props.filter);
}
return (
<View>
{filteredNumbers.map(value => (<Text key={value}>{value}</Text>))}
</View>);
};
}
Usage example:
<FilterNumbers numbers={[1, 2, 3, 4, 5]} filter={value => value % 2 === 1}/>
Additional Notes:
- I've used an Array of numbers for demonstration purposes. You can apply the same concept to an Array of JSON objects by adjusting the logic accordingly.
- It's recommended to utilize ListView to efficiently display iterable data.