1

I am accessing data via an API I would like to display in a list. I am testing VueJS right now and have trouble displaying it properly.

The data is:

{
 "data": [
 {
 "userReference": "R100",
 "responderStatus": 0,
 "location": {
 "latitude": 100,
 "longitude": 100,
 "distance": null
 },
 "featureTypeId": 1
 }
 ],
 "pagination": {
 "total": 1,
 "perPage": 10,
 "lastPage": 1,
 "nextPageUrl": null,
 "prevPageUrl": null,
 "from": 1,
 "to": 1,
 "totalPages": 1,
 "currentPage": 1,
 "hasMorePages": false
 }
}

The HTML:

<div class="wrapper wrapper-content animated fadeInRight">
 <div class="row">
 <div class="col-lg-12">
 <div class="text-center m-t-lg">
 <h1>MEDIFAKTOR server</h1>
 </div>
 <div id="app">
 <ul class="list-group">
 <li v-for="responder in responders">@{{ responder[0] }}</li>
 </ul>
 </div>
 </div>
 </div>
 </div>
 </div>

VueJS:

var app = new Vue({
 el: '#app',
 data: {
 responders: []
 },
 mounted: function() {
 $.get('/api/v1/responders', function(data) {
 app.responders = data;
 })

I only want to display the "userReference" per list item.

Saurabh
73.8k44 gold badges193 silver badges251 bronze badges
asked Feb 5, 2017 at 14:26

1 Answer 1

6

You have to iterate over responders.data as it is the array you have to loop and than you can just access userReference like: {{responder.userReference }}. You should be able to do it like following:

<div id="app">
 <ul class="list-group">
 <li v-for="responder in responders.data">{{ responder.userReference }}</li>
 </ul>
</div>
answered Feb 5, 2017 at 14:30

1 Comment

nice!! Now that I see how, looks easy! :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.