0

I have the following script template:

<script id="template" type="text/x-jsrender">
    <div>
        <label>Name</label>
        <input data-link="FirstName" type="text" />
    </div>


    <button>Search</button>
</script>

I fire jsView with the following command:

$.templates("#template").link("#result", model);

Where model is js object

function myModel() {
    this.FirstName = "";
}

Unfortunately, link command casues error:

TypeError: elem.dispatchEvent is not a function

What could be wrong?

1 Answers1

0

Could it be the way you are constructing your model?

For instance, this doesn't work (fiddle):

function myModel() {
    this.FirstName = "",
}
var model = myModel();
$.templates("#template").link("#result", model);

But this works (fiddle):

var model= {
    FirstName : "",
}

$.templates("#template").link("#result", model);

As does this (fiddle):

function myModel() {
    this.FirstName = "",
}
var model = new myModel(); //<---the new keyword makes the difference
$.templates("#template").link("#result", model);
J.Wells
  • 1,749
  • 12
  • 13
  • Well.. Actually model is got from $.ajax success function. It could be a Solution, but I'd like to avoid rewritng data from ajax callback to custom class. –  May 12 '14 at 15:55
  • Are you using prototype.js in your page? – J.Wells May 12 '14 at 16:04
  • No. Only jQUery and jsView. –  May 13 '14 at 06:31
  • Any chance you can reproduce the problem in a fiddle? – J.Wells May 13 '14 at 16:35
  • "TypeError: elem.dispatchEvent is not a function" doesn't sound like it is happening within JsViews. You'd at least need a fiddle, for us to be able to help you out... – BorisMoore May 13 '14 at 18:08
  • Yeah, but When I remove link function, everything workds. I'll try to reproduce it in a fiddle later. –  May 14 '14 at 06:45
  • 1
    I'm feeling the same way as @BorisMoore. When I looked at the lib code, I didn't see anything throwing a "TypeError: elem.dispatchEvent is not a function" exception. It's prob a browser thing or the result of some lib conflict (something bulldozing something else, perhaps). – J.Wells May 14 '14 at 13:15