Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 从路由(铁路由器)设置反应性数据源会破坏反应性_Meteor_Iron Router - Fatal编程技术网

Meteor 从路由(铁路由器)设置反应性数据源会破坏反应性

Meteor 从路由(铁路由器)设置反应性数据源会破坏反应性,meteor,iron-router,Meteor,Iron Router,我有以下代码在路由器铁路由器 Router.map( function () { this.route('hello',{path:'/hello', onBeforeAction: function(){ console.log("QBConnected"+this.params.qbconnected); Session.set("QBCONNECTED",this.params.qbconnected); } }); }); test.html中的以下代码 <template n

我有以下代码在路由器铁路由器

Router.map( function () {
this.route('hello',{path:'/hello',
onBeforeAction: function(){
console.log("QBConnected"+this.params.qbconnected);
Session.set("QBCONNECTED",this.params.qbconnected);
}
});

});
test.html中的以下代码

<template name="hello">
{{#if QBCONNECTED}}
<h1>Hello World if value={{QBCONNECTED}}</h1>
{{else}}
<h1>Hello World else value={{QBCONNECTED}}</h1>
{{/if}}
{{greeting}}
<input type="button" value="Click" />
</template>
当我尝试使用URL运行此操作时

如果value=true,我会看到字符串Hello World 但是当我尝试url时,我看到了字符串 如果value=false,则为Hello World。有人能解释为什么当QBCONNECTED的值为false时它会进入if块吗

当我尝试按Session.setQBCONNECTED从浏览器控制台手动设置值时,如果value=true,则为true;但当我尝试Session.setQBCONNECTED时,为false,则打印Hello World else value=,有人能解释为什么QBCONNECTED在设置为false时会丢失它的值吗?

之所以发生这种情况,是因为查询字符串中的false被计算为false字符串,而不是您所期望的false布尔值

if (Meteor.isClient) {
//Session.setDefault('QBCONNECTED',false);
Template.hello.greeting = function () {
return "Welcome to test.";
};

Template.hello.events({
'click input': function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
});

Template.hello.QBCONNECTED=function(){
console.log(Deps.active+"get QBCONNECTED called"+Session.get('QBCONNECTED'));
return Session.get('QBCONNECTED');
};
}

if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}