javascript - Dynamically adding HTML dropdowns that are filled by Meteor templates -
i hoping below. i'm very new meteor , trying create contextual dropdown row in jquery/js populated data meteor/mongo.
for example have 1 dropdown listing "areas" , listing "systems". initally areas dropdown visible, depenging on choice made areas dropdown reveal/populate new dropdown called "system".
here excerpts:
html:
<hr> <div class="form-inline"> <div class="form-group"> <div id="area_dropdown" class="dropdown"> <input id="areaval" type="hidden" val="" /> <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">area <span class="caret"></span></button> <ul class="dropdown-menu"> {{> area}} </ul> </div> </div> </div> <hr> <template name="area"> {{#each areas}} <li class="area_dropdown" id="{{id}}">{{alias}}</li> {{/each}} </template> <template name="system"> {{#each systems}} <li class="system_dropdown" id="{{id}}">{{alias}}</li> {{/each}} </template>
js/meteor:
$(document).on("click", ".area_dropdown", function () { var dropdownval = this.id; $('#areaval').val(dropdownval); session.set({ area: dropdownval }); $(this).closest('.dropdown').find('.dropdown-toggle').html($(this).text() + '<span class="caret"></span>'); if (reports.findone({ area: dropdownval })) { $(this).closest('.form-inline').append('<div class="form-group"><div id="system_dropdown" class="dropdown"><input id = "systemval" type = "hidden" val = "" /><button class = "btn btn-default dropdown-toggle" type = "button" data-toggle = "dropdown" >system<span class = "caret" ></span></button><ul class = "dropdown-menu">{{> system}}</ul></div></div>'); } else { $('#system_dropdown').parent().remove(); } } });
the problem lies adding {{> system}} template within .append() has parsed string. i've tried examples online can't tailor needs. can @ all?
Comments
Post a Comment