Three ways to add dropdown options via Javascripts
Method #1 - Via jQuery + html tag
var self = this;
var sel = (self.selected === -1)?true:false;
var option = null;
option = $("");
option.val(-1).prop("selected", sel).text("(None)");
this.$el.append(option);
this.collection.forEach(function(model)
{
sel = (self.selected == model.get('id'))?true:false;
option = $("");
option.val(model.get("id")).prop("selected", sel).text(model.getName());
self.$el.append(option);
});
Method #2 - Via native "Option" object
option = new Option(data.text, data.id, false, false);
this.$('#entropy').append(option).trigger('change');
Method #3 - Just render two <select> and hide the unused one - think outside the box.
This is my preferred method when there are only two sets of valid options
html:
<div class="control-group" id="encoding_profile_row_hevc">
<label class="control-label">Encoding Profile</label>
<div class="controls">
<select name="encodingProfile" class="selectpicker span3" data-style="btn-select-gray" data-size="false" id="encodingProfileHevc">
<option value="2">Main</option>
<% if (systemInfo.get("yuv10bit") === true) {%><option value="6">Main 10</option><% } %>
<% if (systemInfo.get("yuv422") === true && systemInfo.get("yuv10bit") === true) {%><option value="7">Main 4:2:2 10</option><% } %>
</select>
</div>
</div>
<div class="control-group hidden" id="encoding_profile_row_h264">
<label class="control-label">Encoding Profile</label>
<div class="controls">
<select name="encodingProfile" class="selectpicker span3" data-style="btn-select-gray" data-size="false" id="encodingProfileH264">
<option value="1">Baseline</option>
<option value="2">Main</option>
<option value="3">High</option>
<% if (systemInfo.get("yuv10bit") == true) {%><option value="4">High 10</option><% } %>
<% if (systemInfo.get("yuv422") === true) {%><option value="5">High 4:2:2</option><% } %>
</select>
</div>
</div>
onChangeCodec: function() {
var codec = this.$("#codecAlgorithm").val();
if (codec == "0")
{ //h264
this.$("#encoding_profile_row_h264").removeClass("hidden");
this.$("#encoding_profile_row_hevc").addClass("hidden");
}
else
{
this.$("#encoding_profile_row_hevc").removeClass("hidden");
this.$("#encoding_profile_row_h264").addClass("hidden");
}
this.onChangeEncodingProfile();
},
Recent Comments