简体   繁体   中英

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM