我有一个这样的模板:
<div data-bind='template: { name: "stringTemplate", foreach: stringCollection() }'> </div>
</div>
<script id='stringTemplate' type='text/html'>
// I want to display string from collection here
</script>
如何访问模板中的字符串对象?
最佳答案
在 jQuery 模板中,您可以使用 $data
来引用正在绑定(bind)的整个对象。
所以,你会这样做:
<span data-bind="text: $data"></span>
或
${ $data }
关于javascript - 当 foreach 绑定(bind)到字符串列表时如何访问字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6548021/