Search code examples
javascriptmeteorspacebarsmeteor-helper

How Do I Check For Matching Strings When Using Spacebars?


this is my code

<select id="updOrg">
        {{#each organization}}
          <option id="{{_id}}" {{ifSelected ../user.profile.organization}}>{{name}} </option>
        {{/each}}
    </select>

in my template helper my code is

'ifSelected':function(org){
    console.log(org);
    console.log(this.name);
    var name=this.name;
    if(org === this.name){
      console.log("matched");
      return "selected";
    }  
  }

in the console I'm getting

TEST
XXX

TEST
TEST

the second two strings are matching,but here it is not matching in the if condition

and I also I can't see matched in my console.

what is wrong here


Solution

  • You should do it the following way:

    <option id="{{_id}}" selected="{{ifSelected ../user.profile.organization}}">{{name}} </option>
    

    and change ifSelected to return true or false.

    Why "TEST" is not equal to "TEST" I can't say, because they should be. Sure there aren't some empty spaces at the end of one of them?