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

jsrender does not show data in select - options #324

Closed yedduprasasd closed 7 years ago

yedduprasasd commented 7 years ago

Boris, First off let me thank you for the awesome features you have made available via jsRender. For a novice like me in Web Development, it is a great and simple method to build apps.

I have a very simple need to display list of Company IDs for the user to select from. The list is a "select" and I have been able to successfully populate the template and can see the data in the consol.log. However when I render the template at the place holder, the list does not show any options.

There is a class called "chosen-select" on the select tag that is part of the html template I bought and this gives me the right look and feel. If I remove this class, the list is populated, but I am missing out the functionality and look and feel I wish to keep.

How can I continue to use the class and still be able to use jsrender to populate the list.

Below is the code...

---- Placeholder ----
<div class="col-sm-4">
  <select id="companylistplaceholder" class="form-control m-b chosen-select" name="account">              
  </select>
</div>

---- Template ----
<script id="companylisttemplate" type="text/x-jsrender">
  <option>[%>id%]</option>
</script>

---- Icon when clicked calls the AJAX function that intern calls a postgreSQL function via django to get the list of company IDs ----
<div class="ibox-tools">
  {% for imodulesaccess in lmodulesaccess %}
    {% if imodulesaccess.createallowed == 'Y' %}
      <a class="plus-link"><i id="i_adduser"class="fa fa-plus text-navy" data-toggle="modal" data-target="#adduser"></i></a>
    {% endif %}
  {% endfor %}
</div>
---- call to the ajax function ---
$("#i_adduser").click(function(ev){
  getcompanylist();
})

---- AJAX function that calls the Db and get the data ----
    function getcompanylist(){
      $.ajax({
        type: "GET",
        url: "/elahadmin/getcompanylist",
        data: {},
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(lcomanylist){
            console.log(lcomanylist);
            var template = $.templates("#companylisttemplate");
            var companylistdata = template.render(lcomanylist);
            $("#companylistplaceholder").html(companylistdata);
            console.log(companylistdata);
        }
      })
    }

OptionIssue.txt

BorisMoore commented 7 years ago

It seems like JsRender is functioning correctly, and your issue is not coming from JsRender at all.

It looks like you are using other technologies for generating content - some kind of server rendering with templates? I don't know what the {% %} and [% %] markup relates to.

If changing a class makes the options show up, then your issue involves CSS styles - presumably a CSS stylesheet containing "chosen-select" - and associated with the "HTML template you bought". Again, the issue would be with this rather than with JsRender.

BorisMoore commented 7 years ago

I'll close this as not being a JsRender issue or bug. Please add comments if you have further questions that do concern JsRender usage directly... Thanks...

yedduprasasd commented 7 years ago

Boris, The {% %} is for Django based server side interpolation. Thank you for the revert.

My issues is sorted out.

From: Boris Moore [mailto:notifications@github.com] Sent: Saturday, June 17, 2017 11:32 PM To: BorisMoore/jsrender jsrender@noreply.github.com Cc: yedduprasasd yeddu.prasad@yahoo.com; Author author@noreply.github.com Subject: Re: [BorisMoore/jsrender] jsrender does not show data in select - options (#324)

It seems like JsRender is functioning correctly, and your issue is not coming from JsRender at all.

It looks like you are using other technologies for generating content - some kind of server rendering with templates? I don't know what the {% %} and [% %] markup relates to.

If changing a class makes the options show up, then your issue involves CSS styles - presumably a CSS stylesheet containing "chosen-select" - and associated with the "HTML template you bought". Again, the issue would be with this rather than with JsRender.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BorisMoore/jsrender/issues/324#issuecomment-309230612 , or mute the thread https://github.com/notifications/unsubscribe-auth/AStjm1sgUW6IjqX6n0QW_I_dBzIdWixAks5sFBS0gaJpZM4N7LmN . https://github.com/notifications/beacon/AStjmwbuYMrTy1TqvimuWsIX1EqatblZks5sFBS0gaJpZM4N7LmN.gif