javascript - 获取未捕获错误 : Unable to parse bindings in knockout

标签 javascript jquery knockout.js

获取错误

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

http://jsfiddle.net/fNhKp/11/

关于javascript - 获取未捕获错误 : Unable to parse bindings in knockout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22476064/

相关文章:

javascript - 第二个计算函数导致 Knockout 代码出错

javascript - ko.toJSON() 在 MVC 中工作,但在 asp.net FORM 应用程序 "{item:"+ ko.toJSON(Product) + "}"中工作

javascript - TypeScript 中 JavaScript 的等价物

javascript - 使用 AJV 针对 JSON 架构进行 API 验证响应期间出现错误输出

JavaScript 'x is not a function'

php - 如何将Flickr API返回的图像放到不同的页面中?

Javascript 显示/隐藏多个 div 简化

javascript - 格式化和显示从 jQuery 返回的数据?

javascript - 如何使用 ReSTLet 发送(编码)PNG 图像并使用 jQuery 接收(解码)它?

php - PHP MySQL AJAX 中的多个搜索选项