[英]Meteor checkbox always false after Template render
I have a navbar with 2 entries. 我有2个条目的导航栏。 One entrie is a checkbox and the other one is a dropdown with a button (I will provide code for that).
一个条目是一个复选框,另一个是带有按钮的下拉菜单(我将为此提供代码)。 The
input
has the id inputMode
and the button addNewObject
input
具有id inputMode
和按钮addNewObject
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li id="editMode">
<a href="#">
<label><input type="checkbox" value="Edit Mode" id="inputMode">Edit Mode</label>
</a>
</li>
<li><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-haspopup="true" aria-expanded="false">Scenegraph <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><div style="text-align:center;">
<input id="addNewObject" type="button" class="btn-success" value="Add Object">
</div></li>
</ul>
</li>
</ul>
</div>
For each of the id's i have click
function's. 对于每个ID,我都有
click
功能。
'click #inputMode': function (event, tmpl) {
let isChecked = $("#inputMode").is(":checked");
if (isChecked) {
// do something
} else {
//do something
}
},
'click #addNewObject': function (ev) {
Helper.initSceneGraph();
}
So the thing is when i click the button addNewObject
the navbar gets rerendered, like this: 所以事情是当我单击按钮
addNewObject
,导航栏被重新渲染,如下所示:
static initSceneGraph() {
if (Meteor.isClient) {
Template.sceneGraph.helpers({
sceneObjects: Application.getInstance().scene.sceneObjects,
isAudio: function (obj) {
return obj._soundPath;
}
});
}
UI.render(Template.sceneGraph, document.body);
}
So after the initSceneGraph
the checkbox inputMode
doesnt change. 因此,在
initSceneGraph
,复选框inputMode
不会更改。 That means visually it changes, but intern it always stays the same. 这意味着它在视觉上会发生变化,但实习生总是保持不变。 For example
console.log($("#inputMode").is(":checked");
is either ALWAYS false or ALWAYS true, depending if it was true or false BEFORE clicking the button. 例如
console.log($("#inputMode").is(":checked");
始终为false或始终为true,这取决于单击按钮之前是否为true或false。
I hope someone can help me out with this! 我希望有人可以帮助我!
Have you tried using jquery before or after the render? 您是否尝试过在渲染之前或之后使用jquery?
'click #addNewObject': function (ev) {
$('#inputMode').prop('checked', true);
Helper.initSceneGraph();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.