foreach绑定到字符串列表时,如何访问字符串

How to get access to the string when foreach-binding to a list of strings?

本文关键字:字符串 何访问 访问 绑定 列表 foreach      更新时间:2023-09-26

我有一个这样的模板:

<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来引用被绑定的整个对象。

所以,你可以做一些类似的事情:

<span data-bind="text: $data"></span>

${ $data }