获取错误
Uncaught ReferenceError: Unable to parse bindings.
Bindings value: html: typeof rowText == 'function' ? rowText($parent) : $parent[rowText] , attr: {class: [rowText]}
Message: $parent is not defined
在
<tbody data-bind=\"foreach: itemsOnCurrentPage\">\
<tr data-bind=\"foreach: $parent.columns, attr: {id: ItemId},css:{even:$index()%2==0,odd:$index()%2!=0}\">\
<span data-bind=\"html: typeof rowText == 'function' ? rowText($parent) : $parent[rowText] , attr: {class: [rowText]}\"></span>\
</tr>\
</tbody>\
当 span 被替换为 td 标签时,它工作正常。
<tbody data-bind=\"foreach: itemsOnCurrentPage\">\
<tr data-bind=\"foreach: $parent.columns, attr: {id: ItemId},css:{even:$index()%2==0,odd:$index()%2!=0}\">\
<td data-bind=\"html: typeof rowText == 'function' ? rowText($parent) : $parent[rowText] , attr: {class: [rowText]}\"></td>\
</tr>\
</tbody>\
不知何故我需要 span 标签。可以,有人请告诉我,如果使用 span instaed of td 标签,为什么它在绑定(bind)时显示错误。这是一个例子 http://jsfiddle.net/pratbhoir/fNhKp/10/
最佳答案
您不能直接在“tr”下使用 span,它必须在 td 内,这就是您收到错误的原因。所以把 span 放在 td 下。
<tbody data-bind="foreach: itemsOnCurrentPage">
<tr data-bind="foreach: $parent.columns">
<!--ko ifnot: typeof rowText == 'object' && typeof rowText.action == 'function'-->
<td>
<span data-bind="text: typeof rowText == 'function' ? rowText($parent) : $parent[rowText] "></span>
</td>
<!--/ko-->
</tr>
</tbody>
错误
有有限的元素是 HTML 表格元素的有效子元素,它们是:
- 列组,
- 头,
- 脚,
- body ,和
- tr
因此,当您尝试使用 tr 标签内的无效 span 标签验证 html 时,它会给出如下错误:-
Start tag span seen in table.//error invalid html
关于javascript - 获取未捕获错误 : Unable to parse bindings in knockout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22476064/