【发布时间】:2015-10-18 02:48:37
【问题描述】:
我正在尝试在 MeteorJS 中制作一个 SELECT 框形式。每次我更改一个 SELECT 框时,我希望其他 SELECT 框显示不同的值,也许这张图片可以帮助...
我是如何解决的:
"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>
一切正常,但我认为这不是解决此问题的最佳方法。有人有更好的想法吗?将不胜感激。
【问题讨论】:
-
您的具体问题是什么?表现?模块化?如果只是代码风格,那就见仁见智了……
标签: javascript meteor meteor-blaze