使用空格键时如何检查匹配的字符串

How Do I Check For Matching Strings When Using Spacebars?

本文关键字:检查 字符串 空格键 何检查      更新时间:2023-09-26

这是我的代码

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

在我的模板帮助程序中,我的代码是

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

在我得到的控制台中

TEST
XXX
TEST
TEST

后两个字符串匹配,但这里在 if 条件中不匹配

而且我也看不到控制台中的matched

这里有什么问题

您应该按以下方式执行此操作:

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

并将ifSelected更改为返回truefalse

为什么"TEST"不等于"TEST"我不能说,因为它们应该是。确定其中一个的末尾没有一些空白区域吗?