Can I do a jquery-tmpl each over object properties

大兔子大兔子 提交于 2019-12-03 02:46:37

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

{{each(prop, val) myObj}}
      <li><span>${prop}</span> - <span>${val}</span></li>
{{/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/

You can also use this

{{each myObj}}
      <li><span>${$index}</span> - <span>${$value}</span></li>
{{/each}}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!