2

我想更多地了解 HotTowel。

在 ~/App/views/shell.html 中,它包含:

<header>
    <!--ko compose: {view: 'nav'} --><!--/ko-->
</header>

命令是否ko嵌入在 Html 注释标签中?如果是这样,compose 命令做什么以及如何使用参数?

4

1 回答 1

1

Yes. This is a feature of KnockoutJS and it's called "virtual elements". The main advantage is that you don't have to add additional HTML tags if it's unnecessary. It's very useful and it's very clean in some scenarios. Mentioned in few places in Knockout documentation i.e.: http://knockoutjs.com/documentation/with-binding.html and http://knockoutjs.com/documentation/custom-bindings-for-virtual-elements.html

As of compose it's a custom binding and is explained in HotTowel README:

The compose bindings for the header and footer are hard coded in Hot Towel to point to the nav and footer views, respectively. The compose binding for the section #content is bound to the router module's active item. In other words, when you click a navigation link its corresponding view is loaded in this area.

于 2013-09-04T16:30:27.943 回答