Can I do a jquery-tmpl each over object properties

前端 未结 2 2039
孤城傲影
孤城傲影 2021-02-05 21:40

The template {{each}} directive works great for iterating over an array like this:

var myArray = [\"a\",\"b\",\"c\"];

I\'m wondering if there i

2条回答
  •  走了就别回头了
    2021-02-05 21:58

    Actually {{each}} will walk through properties on an object. You can do something like this:

    {{each(prop, val) myObj}}
          
  • ${prop} - ${val}
  • {{/each}}

    Here is a sample in Knockout: http://jsfiddle.net/rniemeyer/rpMsM/

    If you really want to use the foreach option of the template binding, then the only real option is to map the object to an array of objects with key/value properties. Something like this: http://jsfiddle.net/rniemeyer/rpMsM/1/

提交回复
热议问题