.filter problem: TypeError: 'undefined' is not a function
I'm trying to retrieve a specific news item from a JSON array that's stringified and saved in localstorage.
I created this generic service:
codeAppery.get_cache_news_item_js = Appery.createClass(null, {
Code: Select all
init: function (requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process: function (settings) {
settings.beforeSend(settings);
if (this.__requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
var cdata = JSON.parse(localStorage.getItem("json_news"));
var match = cdata.filter(function (item) {
return item.posts.id === settings.data.post_id;
});
settings.success(match);
settings.complete('success');
}
} });/code
This is the data that's stringified and saved to localstorage as 'json_news':
http://schoolsays.co.uk/schools/acref...
The service includes a request parameter named 'post_id' which I've mapped to a localstorage item of the same name.
However, I'm getting the error "TypeError: 'undefined' is not a function" here:
Can anyone see where I'm going wrong here?
The app is shared with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a if you want to take a look at the mapping.
Thanks!