I have a json file which contains 2 objects (1: categories , 2: posts)
In my app i am parsing this json file and get the list of categories and show in a list on categories page but when i go to category details page it is not getting the specific items from posts object.
This is the content of my json file
{
“categories”: [
{
“id”: 1,
“title”: “Get Started”,
“image”: “https:mysite.com/images/c1.jpg”
},
{
“id”: 2,
“title”: “How To”,
“image”: “https:mysite.com/images/c2.jpg”
},
{
“id”: 3,
“title”: “Bonus”,
“image”: “https:mysite.com/images/c3.jpg”
}
],
“posts”: [
{
“id”: 1,
“title”: “Video 1”,
“poster”: “https:mysite.com/images/1p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/1.mp4”,
“type”: “stream”,
“category”: “1”
},
{
“id”: 2,
“title”: “Video 2”,
“poster”: “https:mysite.com/images/2p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/2.mp4”,
“type”: “stream”,
“category”: “1”
},
{
“id”: 3,
“title”: “Video 3”,
“poster”: “https:mysite.com/images/3p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/3.mp4”,
“type”: “stream”,
“category”: “1”
},
{
“id”: 4,
“title”: “Video 4”,
“poster”: “https:mysite.com/images/4p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/4.mp4”,
“type”: “stream”,
“category”: “2”
},
{
“id”: 5,
“title”: “Video 5”,
“poster”: “https:mysite.com/images/5p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/5.mp4”,
“type”: “stream”,
“category”: “2”
},
{
“id”: 6,
“title”: “Video 6”,
“poster”: “https:mysite.com/images/6p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/6.mp4”,
“type”: “stream”,
“category”: “3”
},
{
“id”: 7,
“title”: “Video 7”,
“poster”: “https:mysite.com/images/7p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/7.mp4”,
“type”: “stream”,
“category”: “3”
},
{
“id”: 8,
“title”: “Video 8”,
“poster”: “https:mysite.com/images/8p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/8.mp4”,
“type”: “stream”,
“category”: “3”
},
{
“id”: 9,
“title”: “Video 9”,
“poster”: “https:mysite.com/images/9p.jpg”,
“time”: “08:59”,
“video”: “https:mysite.com/videos/9.mp4”,
“type”: “stream”,
“category”: “3”
}
]
}
and this the the content of my script in template
return {
data: function() {
return {
dataArray: null,
loading: true,
}
},
methods: {
},
on: {
pageBeforeRemove: function () {
var self = this;
var app = self.$app;
},
pageInit: function () {
var self = this;
var app = self.$app;
//debugger
iidd = this.$route.params.id
app.request({
url: 'jsons/myfile.json',
method: 'GET',
timeout:3000,
crossDomain: true,
contentType: "application/json;charset=utf-8",
dataType: 'json',
success(res, xhr){
var result = $.grep(res.posts, function(e){ return e.category == iidd; });
console.log(result)
self.$setState({
dataArray: result,
loading: false,
});
},
error(xhr, status){
self.$setState({
dataArray: xhr,
loading: false,
});
//console.log(xhr,status);
app.dialog.alert('Something went wrong, check your internet connection and try again' ,'Error');
}
})
},
}
}
On categories page, app is getting all the categories from this json file and shows in the app categories page with no error, working fine. By clicking on the category link it navigates to category-details.html page along the selected category id in url. Now i want to get all the items from posts object in the json file for this specific category. The app.request returning all the posts but i only want the posts of specific category. Please help. i am using jquery grep feature but getting error
TypeError: $.grep is not a function. in my app.js file i have var $ = Dom7;