2

Parsing vue.js' docs I can't see any hint that vue.js has something like a ng-repeat-start / ng-repeat-end

Is there a way to archive something like

<table>

  <tr class="weather_warning top" ng-repeat-start="warning in dwd_warnings">
    <td {{warning.valid_from}} → {{warning.valid_to}}</td>
    <td><div style='background:{{warning.color}};'>{{warning.message}}</div></td>
  </tr>

  <tr class="weather_warning bottom" ng-repeat-end>
    <td colspan="2">
      {{warning.description}}<br/>
      <span>Issued on the {{warning.effective}} ({{warning.headline}}). {{warning.ascertain}}</span>
    </td>
  </tr>

</table>

Each warning consists of 2 TRs which go together. One is the top half of the message in the iteration, the other one the lower half. It must be this way, because of some very weird formatting stuff, so there's no way around using 2 TRs for one item. Maybe some tags are off in this example, this is because I had to delete a ton of stuff in order to post it here. Note the colspan="2" in the TD of the second TR, which might give a bit of a hint of the problem which is tackled here.

1 Answer 1

3

Closest thing I can think of is to use a <template>, eg

<template v-for="item in items">
  <header>
    Header {{ item }}
  </header>
  <div class="body">
    Body {{ item }}
  </div>
  <footer>
    Footer {{ item }}
  </footer>
</template

See https://v2.vuejs.org/v2/guide/list.html#v-for-on-a-lt-template-gt

... you can also use a <template> tag with v-for to render a block of multiple elements


Nothing changes with your edit, you just wrap your two <tr> elements in

<template v-for="warning in dwd_warnings">
  <tr class="weather_warning top">
    <!-- etc -->
  </tr>
  <tr class="weather_warning bottom">
    <!-- etc -->
  </tr>
</template>
Sign up to request clarification or add additional context in comments.

7 Comments

@DanielF I think not, at least according to the example here ~ docs.angularjs.org/api/ng/directive/…
I removed my comment, because I saw the error. I'm updating the question now to reflect my specific use-case, give me a minute
I changed the example. As I said, when I commented, I did so erroneously, with a wrong assumption, please check the question again and you will understand my problem.
@DanielF I've updated my answer though nothing has really changed
Just note: you need to specify ":key" property for child elements, not the template tag.
|

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.