Backbone.js的模板实例 [英] Backbone.js templating examples

查看:85
本文介绍了Backbone.js的模板实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加单选按钮作为属性模型和视图在一个模板。

How to add radio button as an attribute to model and view it in a template.

<label>ModemControl:</label>
 <input type="radio" name="modemcontrol" value="0" checked="checked"> off
                        <input type="radio" name="modemcontrol" value="1"> on

我已经完成了创建标签,dropdownbox,textbox.i不知​​道如何做到这一点任何人都可以帮我吗?

i have already completed creating labels,dropdownbox,textbox.i have no idea how to do this can anyone help me?

推荐答案

如果我这样做是正确你有兴趣在检查模型中的某些属性右边的单选按钮。

If I got it right you are interested in checking the right radio button on some attributes in the model.

在这种情况下,你的模板应该像有些

In this case your template should look like somewhat:

<script type="text/template" id="radio-template">
    <input type="radio" <% f == "opt1" ? print("checked") :'' %> >
    <input type="radio" <% f == "opt2" ? print("checked") :'' %> >
    ...
</script>

其中F为模板变量您认为在安装过程中指定的

,如:

where f is the template variable you specified during the view setup, like:

var template = _.template($('#item-template').html(), {f: 'opt2'});
this.$el.html(template);

不是说你可以只使用检查检查=真

修改

那么你的模板应该是这样的:

Then your template should look like:

<script type="text/template">
    <label>Age:</label> <input type="text" name="age" value="<%= age %>">
    <label>Radio:</label> <input type="radio" value="<%= modelAttribute%>">
</script>

这篇关于Backbone.js的模板实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆