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

时间:2014-10-10 07:10:35

标签: javascript meteor spacebars meteor-helper

这是我的代码

<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

这里有什么问题

1 个答案:

答案 0 :(得分:1)

您应该按照以下方式进行:

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

并更改ifSelected以返回truefalse

为什么"TEST"不等于"TEST"我不能说,因为它们应该是。{当然在其中一个的末尾没有一些空格?