我想在MeteorJS中製作一個選擇框的窗體。每次我改變一個選擇框,我想其他的選擇框顯示不同的價值觀,也許這張照片可以幫助... 更新Meteor.js上的視圖的問題
我如何解決它:
"use-strict";
if (Meteor.isClient) {
Session.set('cho',false);
Session.set('cho2',false);
Session.set('cho3',false);
var building=["C1","C2","W1"],
floor= ["4","5","6","38","50"];
Template.body.events({
"change #sel_geb" : function(eve,eva){
var a = $(eve.target).val();
if(a==="C1"){
Session.set('cho', true);
Session.set('cho2',false);
Session.set('cho3', false);
Meteor.flush();
}else if (a ==="C2"){
floor.splice(0,1);
Session.set('cho2', true);
Session.set('cho3', false);
Session.set('cho', false);
Meteor.flush();
}else{
Session.set('cho3', true);
Session.set('cho2', false);
Session.set('cho', false);
}
}
});
Template.etage.helpers({
floor: function(){
if(Session.equals('cho',true)){
return ["4"];
}else if(Session.equals('cho2',true)){
return ["5","6"];
}else if(Session.equals('cho3',true)){
return ["38","50"];
}else{
return ["4"];
}
}
});
模板的文件:
<form>
<div class="form-group">
<label for="exampleInputEmail1">Mitarbeiter</label>
<select class="form-control">
{{> mitarbeiter}}
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Gebäude</label>
<select id="sel_geb" class="form-control" >
{{> gebaeude}}
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Etage</label>
<select class="form-control" id="sel_eta">
{{> etage}}
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Raum</label>
<select class="form-control">
{{> raum}}
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Aufgabe</label>
<select class="form-control">
<option>Aufbau/Prüfung</option>
<option>Abbau</option>
<option>Support</option>
<option>Wöchentlicher Check</option>
<option>täglicher Precheck</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Veranstalltungsname</label>
<input type="text" id="presiname" class="form-control" placeholder="Veranstalltungsname">
</div>
<div class="pull-right">
<button type="submit" class="btn btn-primary">Weiter</button>
<button type="cancel" class="btn btn-danger">Beenden</button>
</div>
</form>
<template name="mitarbeiter">
{{#each names}}
<option>{{this}}</option>
{{/each}}
</template>
<template name="gebaeude">
{{#each building}}
<option>{{this}}</option>
{{/each}}
</template>
<template name="etage">
{{#each floor}}
<option>{{this}}</option>
{{/each}}
</template>
<template name="raum">
{{#each room}}
<option>{{this}}</option>
{{/each}}
</template>
Everyting工作正常,但我不認爲這是解決此問題的最佳方法。有人有更好的想法嗎?將非常感激。
您的具體問題是什麼?性能?模塊化?如果它只是代碼風格,那麼這是一個意見問題... –