Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an array of JSON items, and I am trying to use v-repeat to output it as a series of table rows:

<tr v-repeat="items">
    <td>{{code}} </td>
    <td> {{description}}</td>
    <td>
        {{price}}
    </td>
    <td><input v-model="quantity" type="text" size="4"/></td>
    <td> {{total = price * quantity}}</td>
</tr>

A row with empty cells is output for every item in the JSON - so Vue.js is not getting the property values, even though I have confirmed that they are definitely exist and I can get the values in the v-repeat if I do something like this:

{{items[$index].code}}

I am getting no errors or warnings.

This is the JSON output of my Vue data object:

{ "items":[{
    "id": "408",
    "product_id": "6",
    "description": " item description here... ",
    "price": "1210.26",
    "created_at": "2015-06-04 15:10:14",
    "updated_at": "2015-06-04 15:10:14",
    "quote_id": "32",
    "quantity": "1",
    "code": "PI0055"
}]}
share|improve this question
up vote 1 down vote accepted

I did not initialize the data object:

data: {items: []}

Simple mistake - but the fact that no errors are given, and the fact that you can still access the data in certain ways makes it tricky to figure out.

share|improve this answer

Your code works fine for me:

var data = {
    "items":[{
        "id": "408",
        "product_id": "6",
        "description": " item description here... ",
        "price": "1210.26",
        "created_at": "2015-06-04 15:10:14",
        "updated_at": "2015-06-04 15:10:14",
        "quote_id": "32",
        "quantity": "1",
        "code": "PI0055"
    }]
};

var vue = new Vue({
    el: '#tbl',
    data: data
});
<table id="tbl" border="1">
    <tr v-repeat="items">
        <td>{{code}} </td>
        <td>{{description}}</td>
        <td>{{price}}</td>
        <td><input v-model="quantity" type="text" size="4"/></td>
        <td>{{total = price * quantity}}</td>
    </tr>
</table>
<script src="http://vuejs.org/js/vue.min.js"></script>

share|improve this answer
    
Thanks, just before seeing your answer I realized that I did not initialize the data object! – slickorange Jun 8 '15 at 7:17

And were would this

data: {items: []}

be placed in your code? Top, bottom, middle? Without the location, there's no solution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.