0

I am using Boris Moore jsRender http://www.borismoore.com/ and I am trying to get the instance of each item. Does anyone know how to do that?

//render
$("divName").html(
    $('#templateName').render('data')
);

//get instance. Here is my problem
$(".PriceFromPerHotel").each(function () {
                selectedItem = $.tmplItem(this);
});

By the use of

selectedItem = $.tmplItem(this);

I am getting the error message

Object function (a,b){return new e.fn.init(a,b,h)} has no method 'tmplItem'

EDIT

the no method exception solved by adding the jQuery template library. The problem now is that I am getting an empty object. It doesn't return the instance.

Here is my html code

<script id="templateName" type="text/x-jsrender">
<div class="resultsBox">
        //lot of code has here
        <p class="offerSiloPrice">{{:Currency}} <span class="PriceFromPerHotel"></span></p>                 
</div>

Thanks

profanis
  • 2,741
  • 3
  • 39
  • 49
  • try `selectedItem = $.tmplItem($(this));` or `selectedItem = $(this).tmplItem();` – mgraph Mar 15 '12 at 14:05
  • I tried it but nothing changed. I am getting the error for both ways [Object function (a,b){return new e.fn.init(a,b,h)} has no method 'tmplItem'] – profanis Mar 15 '12 at 14:08
  • you sould [download the plugins](http://github.com/jquery/jquery-tmpl) and call it inside your page – mgraph Mar 15 '12 at 14:12
  • I thought that jquery.tmpl was in the same script file with jsRender. That did the trick. Thanks a lot – profanis Mar 15 '12 at 14:15

1 Answers1

2

tmplItem() is jQuery templates syntax. In JsRender the equivalent is $.view(). There are several examples here http://borismoore.github.com/jsviews/demos/index.html. You should use either JsRender OR jQuery templates. They have different template tags and different APIs.

In JsRender, things are factored differently than in jQuery templates. jQuery templates have a DOM dependency and provide the $.tmplItem() feature. JsRender has no DOM dependency, and does 'pure string-based rendering', which makes if a lot faster for scenarios where you don't need data linking, and you don't need the $.tmplItem() feature of getting from a DOM element to the rendered template it came from.

But if you do want those features, then you include JsViews in your page, - which is a layer on top of JsRender, and provides the equivalent DOM related features of jQuery Templates, and more...

In JsViews, the tmplItem is called a 'View'.

$(selectorOrElement).tmplItem() 

in jQuery templates corresponds to

$(selectorOrElement).view() 

in JsViews.

BorisMoore
  • 8,444
  • 1
  • 16
  • 27