1

I have an arry which contains some array and proporties in it.

Now I want to iterate through the array and create new rows for each of items.

This is what I am doing.

var orderDetails = [{
        "ID": "1",
        "NAME": "Item1",
        "Orders": [
            "ORD001"
        ],
        "Purchases": [
            "RhynoMock",
            "Ember"
        ],
        "ISENABLED": "false"
    },
    {
        "ID": "2",
        "NAME": "Item2",
        "Orders": [
            "ORD002",
            "ORD008"
        ],
        "Purchases": [
            "StufferShop"
        ],
        "ISENABLED": "false"
    }
];

var app = new Vue({
    el: '#ordersDiv',
    data: {
        allOrders: orderDetails
    }
});
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="ordersDiv">
    <table>
        <thead>
            <tr>
                <th>Name</th>
            </tr>
        </thead>
        <tbody>
            <tr v-for="order in allOrders">{{ order.NAME }}</tr>
    </table>

</div>

Getting the error,

[Vue warn]: Error in render: "TypeError: Cannot read property 'NAME' of undefined"

2
  • The error is self-explanatory, there is at least one undefined item in the array. Commented Sep 6, 2018 at 1:17
  • @DecadeMoon, But I have Name property in the array. Commented Sep 6, 2018 at 1:19

1 Answer 1

2

Your HTML is invalid, and it seems that Vue's template compiler or DOM renderer has trouble with it: <tr> must only have <td> or <th> child elements, it cannot have text node children.

Try this instead:

<tr v-for="order in allOrders">
  <td>{{ order.NAME }}</td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

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.