Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Backbone.js模板示例_Javascript_Backbone.js - Fatal编程技术网

Javascript Backbone.js模板示例

Javascript Backbone.js模板示例,javascript,backbone.js,Javascript,Backbone.js,如何将单选按钮作为属性添加到模型并在模板中查看它 <label>ModemControl:</label> <input type="radio" name="modemcontrol" value="0" checked="checked"> off <input type="radio" name="modemcontrol" value="1"> on 模式控制: 关 在…上 我已经完成了

如何将单选按钮作为属性添加到模型并在模板中查看它

<label>ModemControl:</label>
 <input type="radio" name="modemcontrol" value="0" checked="checked"> off
                        <input type="radio" name="modemcontrol" value="1"> on
模式控制:
关
在…上

我已经完成了标签、下拉框、文本框的创建。我不知道该怎么做。有人能帮我吗?

如果我做对了,您有兴趣在模型中的某些属性上选中正确的单选按钮

在这种情况下,您的模板应该类似于:

<script type="text/template" id="radio-template">
    <input type="radio" <% f == "opt1" ? print("checked") :'' %> >
    <input type="radio" <% f == "opt2" ? print("checked") :'' %> >
    ...
</script>
并不是说您只能使用
checked
checked=“true”

编辑

那么您的模板应该如下所示:

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

年龄:
电台:

wat u r r告诉s为了检查,我必须创建单选按钮。在上面的示例中,我创建了两个单选按钮。你的意思是,你必须动态地创建单选按钮吗?不检查你能告诉我如何添加单选按钮作为模型属性并在模板Person=Backbone.model.extend({})中查看它吗;var person=new person({name:'Thomas',age:37}),//在模板中//将添加age:now年龄文本框现在我想这样创建收音机buttons@user2082957我编辑了我的答案。我不确定我是否完全理解你的问题。
<script type="text/template">
    <label>Age:</label> <input type="text" name="age" value="<%= age %>">
    <label>Radio:</label> <input type="radio" value="<%= modelAttribute%>">
</script>