xiaolizi007
11/22/2016 - 7:36 AM

template ${ someValue } — 参考文档 {{html someValue}} — 参考文档 {{if someCondition}} — 参考文档 {{else someCondition}} — 参考文档 {{each someArray}} — 参考文档

template ${ someValue } — 参考文档 {{html someValue}} — 参考文档 {{if someCondition}} — 参考文档 {{else someCondition}} — 参考文档 {{each someArray}} — 参考文档

<div data-bind='template: "personTemplate"'> </div>
<script id='personTemplate' type='text/html'>
    ${ name } is ${ age } years old
    <button data-bind='click: makeOlder'>Make older</button>
</script> 

<script type='text/javascript'>
    var viewModel = {
        name: ko.observable('Bert'),
        age: ko.observable(78),
        makeOlder: function () {
            this.age(this.age() +1);
        }
    };
    ko.applyBindings(viewModel);
</script>