0

这里有点高要求,但我想将此数组/集合传递给车把

  var thisWeek = {
    date: "18-3-13",
    comment: "Run through days of the week",
    days:[{
    monday:[
      {vehicle: "Number 1", driver: "Jack_Franklin", events: "Boat Race"},
      {vehicle: "Number 2", driver: "Paul Smith", events: "Racing"},
      {vehicle: "Number 3", driver: "Andrew Kay", events: "Skiing"} 
      ],
    tuesday:[
      {vehicle: "Number 1", driver: "Jack_Franklin", events: "pick up trailer"},
      {vehicle: "Number 2", driver: "Paul Smith", events: "MOT "},
      {vehicle: "Number 3", driver: "Andrew Kay", events: "Park up for day"} 
      ],
    }],
  }

我想做的是遍历一周中的几天并列出那天的所有车辆,例如-

    <script id="ajax-comment" type="text/x-handlebars-template">

    {{#each days}}
    <h2> {{ The day of the week ie Monday - Tuesday etc}}  </h2> 

           {{# each vehicle in monday etc }} 
             {{vehicle}}: {{driver}} : {{events}} <br/>
           {{/each }} 

    {{/each }}  

    </script>

我可以传递一个仅包含星期一详细信息的数组,它对我有用,但无论如何我可以一次做很多事情吗?理想情况下,我想在大约 20 天内传递每天大约 15 辆车的详细信息。希望这有意义吗?,有什么帮助吗?

4

1 回答 1

2

...假设您可以将结构更改为:

{
    days: [{
        day: "Monday",
        vehicles: [{vehicle: "Number 1", driver: "Jack_Franklin", events: "pick up trailer"}]
    }, {
        day: "Tuesday",
        vehicles: [{vehicle: "Number 1", driver: "Jack_Franklin", events: "pick up trailer"}]
    }]
}

...您应该可以这样做;

{{#each days}}
    <h2>The day of the week is {{day}} </h2>

    {{#each vehicles}}
        {{vehicle}}: {{driver}} : {{events}} <br />
    {{/each}}
{{/each}}
于 2013-03-18T22:51:15.217 回答