这是我的代码
<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
。
这里有什么问题
答案 0 :(得分:1)
您应该按照以下方式进行:
<option id="{{_id}}" selected="{{ifSelected ../user.profile.organization}}">{{name}} </option>
并更改ifSelected
以返回true
或false
。
为什么"TEST"
不等于"TEST"
我不能说,因为它们应该是。{当然在其中一个的末尾没有一些空格?