I have a javascript object that needs to be displayed in paged format. For example, from the below object, I need to display this as pages based on the value of perPage variable.
{
"fruits":[
{
"from":"Shanghai",
"to":"Houston",
"createdOn":"2019-02-20 17:02:45",
"threadId":"1234564534"
},
{
"from":"Mumbai",
"to":"Texas",
"createdOn":"2019-02-22 17:02:45",
"threadId":"223455678"
}
],
"vegetables":[{
"from":"Barcelona",
"to":"Milan",
"createdOn":"2019-01-20 10:02:45",
"threadId":"45673456"
}],
"paper":[{
"from":"Kualalumpur",
"to":"Singapore",
"createdOn":"2019-02-01 12:02:45",
"threadId":"234222345"
},
{
"from":"Singapore",
"to":"Vancover",
"createdOn":"2019-01-20 11:02:45",
"threadId":"6756434343"
}],
"books":[{
"from":"Jibooty",
"to":"Ahmedabad",
"createdOn":"2019-02-10 17:02:45",
"threadId":"23456789"
}],
"toys":[{
"from":"Shanghai",
"to":"Houston",
"createdOn":"2019-02-20 14:02:45",
"threadId":"123434343"
}],
"electronics":[{
"from":"Somalia",
"to":"Angora",
"createdOn":"2019-02-20 17:02:45",
"threadId":"667676767"
}]
}
If the value of perPage is 5, this should shown as below
<div class="page">
fruits
vegetables
paper
books
toys
</div>
<div class="page">
electronics
</div>
and if the value of perPage is 2, there will be three div's with the class page. fruits and vegetables will be displayed in the first div, paper and books will be displayed in the second div, toys and electronics will be displayed in the third div.
I have prepared a basic code for this in vue js, but it failed in some cases. Can someone have a look at this and let me know where it went wrong ?
<div class="wrapper">
<div v-for="(eachWidget, widgetName, index) in widgetData">
<div v-bind:class="((index != 0) && ((index%perPage) == 0))?'page':''" >
<div class="widget">
<p>{{ widgetName}}</p>
<p class="card" v-for="(eachItem, index) in eachWidget">{{eachItem.from}}</p>
</div>
</div>