Pratik Bhoir
Pratik Bhoir

Reputation: 2144

Getting Uncaught Error: Unable to parse bindings in knockout

Getting an errror

Uncaught ReferenceError: Unable to parse bindings.
Bindings value: html: typeof rowText == 'function' ? rowText($parent) : $parent[rowText] , attr: {class: [rowText]}
Message: $parent is not defined

on

    <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>\

when the span is replaced with the td tag, it works fine.

    <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>\

I need span tag over there somehow. Can, anybody please tell me, why it shows error while binding if used span instaed of td tags. Here is a example http://jsfiddle.net/pratbhoir/fNhKp/10/

Upvotes: 1

Views: 314

Answers (1)

Akhlesh
Akhlesh

Reputation: 2399

You can not have span directly under 'tr' it must be inside td and that is why you are getting error. so put span under 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>

Error

There are limited elements that are valid children of the HTML table element, these are:

  • colgroup,
  • thead,
  • tfoot,
  • tbody, and
  • tr

so when you will try to validate html with invalid span tag inside tr tag it will give error like:-

 Start tag span seen in table.//error invalid html

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

Upvotes: 2

Related Questions