knockout需要注意的

1. 需要计算的时候,观察的变量加括号,例如 在foreach里面 $index 加1 写成 $index()+1

 例如获取数组的长度的时候,加括号 listA().length。但是如果这个数组没有被ko.observableArray 那么 就不用加括号。

2.没有标签的时候用注释

<!-- ko text:xiangMuBianHao --><!-- /ko -->

3.在table中写的时候碰到 Cannot find closing comment tag to match 是因为table中少了一层 <tbody>.如下,参考:http://stackoverflow.com/questions/18727897/knockout-error-cannot-find-closing-comment-tag-to-match


17
down vote
I have encountered the same issue except with table tags.

Doesn't work - produces the same issue as indicated by Mauricio

<table>
<!-- ko: foreach: { data: SomeData, as: 'item' } -->
<tr>
<td data-bind="text: item"></td>
</tr>
<!-- /ko -->
</table>
Works:

<table>
<tbody>
<!-- ko: foreach: { data: SomeData, as: 'item' } -->
<tr>
<td data-bind="text: item"></td>
</tr>
<!-- /ko -->
</tbody>
</table>
 

4. 可以再if中写自己的函数。<!-- ko if:isNotBlank(fuJianGuid()) --><!-- /ko --> 
--------------------- 
作者:laokaizzz 
来源:CSDN 
原文:https://blog.csdn.net/laokaizzz/article/details/48295967?utm_source=copy 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/seanxwq/article/details/83113954