tes*_*dtv -1 javascript backbone.js underscore.js underscore.js-templating
我的 BackboneJS 模板中有以下代码(使用 Underscore 渲染)
<input type="radio" class="isMale" id="isMaleVolunteersNo"
<%= model.attributes.isMaleVolunteers == undefined ||
model.attributes.isMaleVolunteers == null ||
model.attributes.isMaleVolunteers == 'N' ? 'checked' : ''
%>
name="isMaleVolunteers" value="false" />
<label for="isMaleVolunteersNo" style="display:inline">No</label>
Run Code Online (Sandbox Code Playgroud)
当模型属性 isMaleVolunteers 未定义时,我希望默认选中“否”。
我尝试了以下(带括号)...仍然不起作用;
<input type="radio" class="isMale" id="isMaleVolunteersNo"
<%= (model.attributes.isMaleVolunteers == undefined ||
model.attributes.isMaleVolunteers == null ||
model.attributes.isMaleVolunteers == 'N') ? 'checked' : ''
%>
name="isMaleVolunteers" value="false" />
<label for="isMaleVolunteersNo" style="display:inline">No</label>
Run Code Online (Sandbox Code Playgroud)
但上面的代码不起作用。代码有问题吗?
在 Underscore Template 中用于<% %>执行 javascript 代码。<%= %>用于插入变量(简称变量)所以你的代码应该看起来像<input type="radio" <%if(condition){print('checked');}%> >
| 归档时间: |
|
| 查看次数: |
5376 次 |
| 最近记录: |