BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.67k stars 339 forks source link

How can I load data from jsrender template and update it #370

Closed vigneshsoman closed 1 year ago

vigneshsoman commented 1 year ago

I'm working on migrating Jquery template with JSRender library. I need to retrieve data object from the template page and after that I need to update corresponding property. My old jquery.tmpl code is given below:

JavaScript

function updateItem(event) {
  var $tmplItem = $(this).tmplItem();
  $tmplItem.data.showItem = !$tmplItem.data.showItem;
  $tmplItem.update();
}

html

{{if showItem}}
 <div>
  This is your item.
 </div>
{{else}}
 <div>
  No item.
 </div>
{{/if}}

How can I convert this code into jsRender. I did the following:

JavaScript

function updateItem(event) {
  var $tmplItem = $(this).view().ctx.root[0];
  $tmplItem.showItem = !$tmplItem.showItem;
  //$tmplItem.update();
}

$(this).view() method from JSviews will helps to retrieve the data from the template. But it is not the exact result which I got from $(this).tmplItem(). But there is no update() method. Is there any solution to rebind the updated showItem property to template? Please see my question on stackoverflow https://stackoverflow.com/questions/74155152/how-can-i-load-data-from-jsrender-template-and-update-it

BorisMoore commented 1 year ago

This is not really an 'issue' - more of a request for guidance, which is a duplicate of the same question asked on Stack Overflow, and answered here: https://stackoverflow.com/a/74215858/1054484

BorisMoore commented 1 year ago

Closed as resolved question