ko.applyBindings({
myItems: [ 'A', 'B', 'C' ]
}, document.getElementById("Demo5"));
<h1>演示 KnockOut control flow</h1>
<hr />
<ul>
<li class="Point">
5、<b class="PointTitle"><span class="KeyWord">不使用容器</span>绑定</b><br />
<ul class="PointDesc">
<li>如果你要直接显示一个数组,而不需要任何的容器,则可以使用这种方法</li>
<li>使用Html注释进行书写</li>
</ul>
<div class="PointDemo" id="Demo5">
<ul>
<li class="header">请使用开发人员工具查看DOM元素,发现其中的不同</li>
<!-- ko foreach: myItems -->
<li>Item <span data-bind="text: $data"></span></li>
<!-- /ko -->
</ul>
</div>
<!--下面写一些特殊的提示信息-->
<div class="PSFrame">
这个特性可以让你在任意场景下使用foreach绑定,不需要容器元素
</div>
<hr />
</li>
</ul>
<hr />
/*Demo�ļ���ʽ*/
body
{
background-color: #e3e5d4;
}
/* ֪ʶ�� */
.Point
{
margin: 20px,0,0,0;
}
/* ֪ʶ����� */
.PointTitle
{
color:#0d8d0d;
}
/* �ؼ��� */
.KeyWord
{
color:Red;
}
/* ֪ʶ������ */
.PointDesc
{
font-family: Arial;
font-size: 15px;
color:#09acb8;
}
.PointDesc li
{
margin: 10px,0,0,0;
}
/* ֪ʶ��Demo��� */
.PointDemo
{
border-style:double;
border-color:#dcd559;
min-height:100px;
font-family: Corbel;
font-size: 20px;
color: #00174f;
}
/* ��Ҫ������ʾ����Ϣ��� */
.PSFrame
{
border-style: dashed;
border-color:#78e6ef;
font-family: Corbel;
font-size: 20px;
font-style:italic;
color: #b86c00;
}
/* ������ʾ */
.error {
color:Red;
}
/* ********************************************************** */
/*��Ҫǿ������ʽ*/
.Notice
{
font-weight: bold;
font-family:Bodoni MT Black;
color: #cd0707;
}
/* ********************************************************** */
/*�������ʽ*/
input[type="text"]
{
min-width:250px;
}
select
{
min-width:400px;
}
External resources loaded into this fiddle: