Ho un menu a discesa, ma quando un utente seleziona un altro valore, voglio che venga eseguito del codice. La mia domanda: come posso verificare se il valore selezionato del menu a discesa è cambiato?Meteor - update var on select change
Nel mio file html:
<template name="jaren">
<form id="yearFilter">
<select class="selectpicker span2" id="yearpicker" >
{{#each jaren}}
{{#if selectedYear}}
<option selected value="{{_id}}">{{jaar}} {{description}}</option>
{{else}}
<option value="{{_id}}">{{jaar}} {{description}}</option>
{{/if}}
{{/each}}
</select>
</form>
</template>
nel mio file javascript:
Template.jaren.jaren = function() {
return Years.find();
}
Template.jaren.selectedYear = function() {
if (Session.get('year_id') == this._id) {
return true;
} else {
return false;
}
}
Template.jaren.events({
'change form#yearFilter #yearpicker': function(event, template) {
Session.set('year_id', template.find('#yearpicker').value);
console.log("value changed");
}
});
Il problema iniziale era che Bootstrap selectpicker (https://github.com/silviomoreto/bootstrap-select) rompe il gestore di eventi, in modo che meteorite mai viene a sapere che i dati è stato modificato :(. –
Puoi semplicemente: 'console.log (e.target.value);' senza usare jQuery. –
'console.log (e.target.value);' non funzionerà, perché select non ha valore. Ha selezionato le opzioni come bambini e hanno valori. Devi usare 'currentTarget.options [currentTarget.selectedIndex] .value'. –