我想使用 jsRender 模板来fullName
渲染firstName + ' ' + lastName
. 它不是用数据呈现模板,而是呈现为{{=firstName}} {{=lastName}}
. 我怎样才能使这项工作?
现场示例:http: //jsbin.com/inijay/2/edit
JS:
var data = { "firstName": "Ian", "lastName": "Davis" };
var viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
HTML:
<input data-bind="value: firstName" type="text" />
<input data-bind="value: lastName" type="text" />
<span data-bind="template: 'fullNameTemplate'"></span>
模板:
<script id="fullNameTemplate" type="text/x-jquery-tmpl">
{{=firstName}} {{=lastName}}
</script>
输出的样子: