Question

Iam having a table using bootstrap components with each row clickable am also using handlebars inside table rows

<tbody data-link="row" class="rowlink">

 {{#each model.pastreqlist}}

{{#if_eq {{status}} "PENDING"}} 

<tr  data-toggle="modal" data-target="#pastreq {{action "selectRow" this target="view"}}">

{{else}}

<tr>  

{{/if_eq}}
        <td>{{employee_name}}</td>
        <td>{{type_id}}</td>
        <td>{{from_date}}</td>
       </tr>
      {{/each}}
    </tbody>

i want to enable the content inside tr i.e i want to pop up modal for only those rows which is having status as "PENDING"

so far i have tried this but its not working

here's my helper code also

Handlebars.registerHelper('if_eq', function(a, b, opts) {
if(a == b)
    return opts.fn(this);
else
    return opts.inverse(this);
});

here is my controller code

App.LinksController = Ember.ObjectController.extend({
  actions: {
    myleavesinfolist: function () {
      rdata = $.ajax({
    type: "POST",
    url: "/myleaves",
    dataType: "json",
    async: false
      }).responseJSON;
      this.transitionToRoute("myleaves", rdata);
    } //myleavesinfolist
  } //actions
}); //controller

please help am a newbie to handlebars and ember js

Was it helpful?

Solution

i used handlebars registerhelper in my script as below

Ember.Handlebars.registerHelper('ifeq', function(a, b, options) {
  return Ember.Handlebars.bind.call(options.contexts[0], a, options, true,     function(result) {
    return result === b;
  });
});

and in my template i have done like this

      {{#each model.pastreqlist}}
        {{#ifeq status "PENDING"}}
          <tr  data-toggle="modal" data-target="#pastrequestsmodal" {{action "selectRow" this target="view"}} style="cursor: pointer">
        {{else}}
          <tr>
        {{/ifeq}}

OTHER TIPS

You should set up a computer property on your model, like this:

App.Request = Ember.Model.extend({
    stats:DS.attr('string'),
    isPending:function(){
        if(this.get('status') === 'PENDING'){
            return true;
        }
    }.property('status')
});

Then in your template, you can do it like this:

<tbody data-link="row" class="rowlink">
    {{#each model.pastreqlist}}
        {{#if isPending}} 
            <tr  data-toggle="modal" data-target="#pastreq" {{action "selectRow" this target="view"}}>
        {{else}}
            <tr>  
        {{/if}}
            <td>{{employee_name}}</td>
            <td>{{type_id}}</td>
            <td>{{from_date}}</td>
        </tr>
    {{/each}}
</tbody>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top