根据选择的下拉Backbone.js的更改文字 [英] Backbone.js Change Text based on selected dropdown
问题描述
我想获得一些文本,当用户选择一个下拉框不同的选项来改变。我使用Backbone.js的,我试图找出如何获取文本属于道当用户选择一个选项。
作为后续,如果我没有设置track.text期权的价值,而是track.title,我如何能够从js文件怎么做呢?我原本设定track.title和track.text在JSON文件。我想了解如何获得从JSON文件的信息。谢谢!
window.LibraryLessonView = LessonView.extend({
事件:{
变.sel:changeText
},changeText:功能(){
//不知道我应该写在这里...
}
});
这是在我的HTML文件:
<脚本类型=文/模板ID =教训模板>
<跨度类=课标题><%=标题%GT;< / SPAN>
<选择类=选择>//从JSON文件的曲目,把他们都在下拉列表
<%_.each(轨道,函数(轨道){%GT;
<期权价值=<%= track.title%GT; ><%= track.title%GT;< /选项>
&所述;%}); %GT;
< /选择>&所述p为H.;胡说< / P> //我想在这里更改文本 < / SCRIPT>
应为你工作:
changeText:功能(E){
警报(e.target.value);
}
e.target
指的是在这里触发change事件的DOM元素。 e.target.value
在选择框中返回当前所选项目的值
I am trying to get some text to change when the user selects a different option in a dropdown box. I am using Backbone.js and am trying to figure out how to get the text belonging to the track when the user chooses an option.
As a follow-up, if I didn't set the value of the option to track.text, but rather track.title, how would I be able to get it from the .js file? I had originally set track.title and track.text in a JSON file. I am trying to learn how to get information from the JSON files. Thanks!!
window.LibraryLessonView = LessonView.extend({
events: {
"change .sel " : "changeText"
},
changeText: function() {
//not sure what I should write here...
}
});
This is in my HTML file:
<script type="text/template" id="lesson-template">
<span class="lesson-title"><%= title %></span>
<select class="sel">
//get the tracks from the JSON file and put them all in the dropdown
<% _.each(tracks, function(track) { %>
<option value = <%= track.title %> ><%= track.title %></option>
<% }); %>
</select>
<p> Blah </P> //I want to change the text here
</script>
[EDITED] that should work for you:
changeText: function(e) {
alert(e.target.value);
}
e.target
refers to DOM element that triggers change event here. e.target.value
returns value of currently selected item in select box
这篇关于根据选择的下拉Backbone.js的更改文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!