Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
Javascript 集合布尔值为';t设置为假-流星_Javascript_Jquery_Json_Meteor - Fatal编程技术网

Javascript 集合布尔值为';t设置为假-流星

Javascript 集合布尔值为';t设置为假-流星,javascript,jquery,json,meteor,Javascript,Jquery,Json,Meteor,简而言之,我正在开发的应用程序是一个使用Meteor的公交时刻表应用程序,作为一个实践项目 在my body.js中,我有一个每秒运行一次的间隔,用于获取当前时间并与集合中的项目进行比较 为了显示相关的时间,我添加了一个isActive布尔值,每当集合的当前时间=sartTime时,它就会将其设置为true,这样就可以正常工作。 但是,当我对endTime执行相同的操作并尝试将其设置为false,以便隐藏该时间段时,它就不起作用了。即使是控制台也不会出现。我错过了什么?我最近刚开始做meteor

简而言之,我正在开发的应用程序是一个使用Meteor的公交时刻表应用程序,作为一个实践项目

在my body.js中,我有一个每秒运行一次的间隔,用于获取当前时间并与集合中的项目进行比较

为了显示相关的时间,我添加了一个isActive布尔值,每当集合的当前时间=sartTime时,它就会将其设置为true,这样就可以正常工作。 但是,当我对endTime执行相同的操作并尝试将其设置为false,以便隐藏该时间段时,它就不起作用了。即使是控制台也不会出现。我错过了什么?我最近刚开始做meteor,所以请原谅我的冗余。 值得注意的是,我比较的时间是从CSV文件导入的时间,所以它们必须是00:00am/PM格式

非常感谢你们抽出时间

Body.js代码:

Template.Body.onCreated(function appBodyOnCreated() {
    Meteor.setInterval(() => {
      var h = (new Date()).getHours();      
      const m = ((new Date()).getMinutes() <10?'0':'') + ((new Date()).getMinutes());    
      var ampm = h >= 12 ? ' PM' : ' AM';
      ampmReac.set(ampm);

      if (h > 12) {
          h -= 12;
      } else if (h === 0) {
         h = 12;
      }
      const timeAsAString = `${h}${m}`;
      const timeAsAStringFormat = `${h}:${m}`; 
      whatTimeIsItString.set(timeAsAStringFormat + ampm);                // convert to a string
      const timeAsANumber = parseInt(timeAsAString);    // convert to a number
      whatTimeIsIt.set(timeAsANumber);                  // update our reactive variable


        if (Timetables.findOne({TimeStart: whatTimeIsItString.get()}).TimeStart == whatTimeIsItString.get())
        {
        var nowTimetable = Timetables.findOne({TimeStart: whatTimeIsItString.get() });
          Timetables.update({_id : nowTimetable._id },{$set:{isActive : true}});
          console.log('I am inside the START statement');


        }  

        else if (Timetables.findOne({TimeEnd: whatTimeIsItString.get()}).TimeEnd == whatTimeIsItString.get())
        {
        var nowTimetable = Timetables.findOne({TimeEnd: whatTimeIsItString.get() });
          Timetables.update({_id : nowTimetable._id },{$set:{isActive : false}});
          console.log('I am inside the END statement');


        }  


    }, 1000);  //reactivate this function every second
 });
})
Template.Body.onCreated(函数appBodyOnCreated()){
流星时间间隔(()=>{
var h=(新日期()).getHours();
常量m=((新日期()).getMinutes()=12?'PM':'AM';
ampmReac.set(ampm);
如果(h>12){
h-=12;
}else如果(h==0){
h=12;
}
const timeasasString=`${h}${m}`;
常量TimeAsStringFormat=`${h}:${m}`;
whatTimeIsItString.set(timeasasstringformat+ampm);//转换为字符串
const timeAsANumber=parseInt(timeasasString);//转换为数字
whatTimeIsIt.set(timeAsANumber);//更新反应变量
if(Timetables.findOne({TimeStart:whatTimeIsItString.get()})。TimeStart==whatTimeIsItString.get())
{
var nowthemation=Timetables.findOne({TimeStart:whattimeiitstring.get()});
Timetables.update({u id:nowthemation.{u id},{$set:{isActive:true}});
log('我在START语句中');
}  
else if(Timetables.findOne({TimeEnd:whattimeiitstring.get()})。TimeEnd==whattimeiitstring.get())
{
var nowthemation=Timetables.findOne({TimeEnd:whattimeiitstring.get()});
Timetables.update({u id:nowthemation.{u id},{$set:{isActive:false}});
log(“我在结束语句中”);
}  
},1000);//每秒重新激活此函数
});
})

很可能只是您的
if
/
else
阻塞了您所要求的:

  • 它尝试在
    时间表
    中查找具有指定的
    TimeStart
    的文档。如果是,则将此文档设置为“活动”

  • 如果以前未找到任何文档,即没有
    TimeStart
    等于当前时间的时隙,则它会尝试查找具有指定
    TimeEnd
    的文档

  • 但是只有在前面的
    if
    块没有找到任何内容时,才会执行
    else if

    因此,如果您有一个在当前时隙结束时开始的下一个时隙,则会为该下一个时隙执行
    if
    块,但不会执行
    else if
    块以取消激活当前时隙


    一个简单的解决方案是将
    else if
    块转换为一个独立的
    if
    块,这样就可以测试前一个块(即TimeStart)是否找到了什么东西。

    好,所以我最终让它工作了。我的问题是,它永远不会进入第二个
    IF
    语句。 我所做的是设置一个全新的Meteor.interval(()>)函数,并将第二个
    IF
    按原样放在那里


    我认为问题在于,它检查第一个
    IF
    语句,然后卡在那里,不管参数的结果如何。

    将时间作为字符串处理只是一场噩梦。我建议您将时间字符串转换为实际时间(UTC),并以这种方式存储它们,然后使用实际时间。你的代码会简单得多。你能给我一个如何做的例子吗?如果我做对了:从数据库中提取时间,将其放入变量中,将变量转换为UTC日期,然后从那里执行操作?不幸的是,这是我尝试的第一件事。还是不行。我注意到它没有读“TimeEnd”。我尝试了console.log TimeEnd,但它没有得到它。我认为问题在于形式;只是找不到。如果您不描述您在问题中尝试了什么,我们将无法提供相关帮助。正如我在下面的评论中所解释的,我最终设法解决了它。谢谢你对我的耐心,编码不是我的最佳选择,但我正在努力:)没问题,我很高兴你自己找到了解决方案!很高兴在此分享您的解决方案,以防其他人面临类似情况。继续努力!