0

I am new to Vue js.

I am trying to parse json into the html table with

<tr v-for="(item) in products">
   <td>{{item.id}}</td>
</tr>

but the table prints empty rows. and if i try to print

<td>{{item}}</td>

then each row print single character of the json.

my json : "{id: 'mu'}"

here is the screenshot of the table that prints single character

where I am wrong. Please, a little guidance would help.

var app4 = new Vue({
el: '#Itemlist',
data: {
    products: []
},

mounted: function (){
    var self = this;
    $.ajax ({
        url: "getAll",
        method: "GET",
        success: function (data) {
            self.products = "{id: 'mu'}";
        },
        error: function(error) {
            console.log(error)
        }
    });
}

})
3
  • the products variable needs to be an array, so [{id: 'mu'}] Commented May 8, 2018 at 11:22
  • @ChrisDixon I tried this too, but now 2 more empty rows are added. Commented May 8, 2018 at 11:24
  • You're setting products to a string, rather than an array... I'll add the answer. Commented May 8, 2018 at 11:35

1 Answer 1

1
var app4 = new Vue({
el: '#Itemlist',
data: {
    products: []
},

mounted: function (){
    var self = this;
    $.ajax ({
        url: "getAll",
        method: "GET",
        success: function (data) {
            // this is your issue
            //self.products = "{id: 'mu'}";

            self.products.push({id: 'mu'});
        },
        error: function(error) {
            console.log(error)
        }
    });
}

})
Sign up to request clarification or add additional context in comments.

1 Comment

No problem! Happy to help.

Your Answer

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.