首页 \ 问答 \ 无法将Meteor集合中的数据放入数组中(Can't put data from a Meteor collection into an array)

无法将Meteor集合中的数据放入数组中(Can't put data from a Meteor collection into an array)

我正在学习Meteor,我试图将Collection.find()的结果传递给数组(使用变量),而我所拥有的更简单的代码(在根目录中的文件中):

    CalEvents = new Mongo.Collection('calevents');    //creating a collection 

/*------------------------- Populating the database with dummy data-------*/
    if (Meteor.isServer) {                            
    Meteor.startup(function () {
        if (CalEvents.find().count() === 0) {
          CalEvents.insert({
                title: "Initial room",
                start: '2010-02-02'
          });
        }
      });
    }
  /*--------------- Creating an array from the collection-----------------*/
    events = [];
    calEvents = CalEvents.find({});
    calEvents.forEach(function(evt){
        events.push({
            title: evt.title,
            start: evt.start,
        })
    });

该页面没有任何显示,但使用我可以看到的控制台(CalEvents.find(。。fetch()),我在我的数据库中有数据,但“事件”变量是空的...我不明白为什么因为我尝试了其他一些事情,比如更改文件名和移动代码以保证正确的顺序。 我已经尝试使用CalEvents.find()。fetch()来创建一个数组,将结果放入变量但是我无法做到......有谁知道什么是如此简单以至于我错过了? ...


I'm learning Meteor and I was trying to pass the result of a Collection.find() into and array (using a variable) and the simpler code I have is (in a file that is in the root):

    CalEvents = new Mongo.Collection('calevents');    //creating a collection 

/*------------------------- Populating the database with dummy data-------*/
    if (Meteor.isServer) {                            
    Meteor.startup(function () {
        if (CalEvents.find().count() === 0) {
          CalEvents.insert({
                title: "Initial room",
                start: '2010-02-02'
          });
        }
      });
    }
  /*--------------- Creating an array from the collection-----------------*/
    events = [];
    calEvents = CalEvents.find({});
    calEvents.forEach(function(evt){
        events.push({
            title: evt.title,
            start: evt.start,
        })
    });

The page has nothing to show but using the console I can see (CalEvents.find().fetch()) that I have data in my database but the "events" variable is empty... I can't understand why because I tried several other things such as changing file names and moving code to guarantee the proper order. And I already tried to use CalEvents.find().fetch() to create an array an put the result into a variable but I'm not able to do it... Does anyone know what's so simple that I'm missing?...


原文:https://stackoverflow.com/questions/28353240
更新时间:2024-02-18 13:02

最满意答案

(来自regexplib.com )将匹配你想要的,并执行闰年,每月每天等的检查。它比你想要的更容忍分隔符,但这可以很容易地修复。 如你所见,它相当可怕。

或者(最好在我看来)你可能只想检查正确位置的数字,然后在代码中执行闰年和每月每日检查。 有时一个正则表达式不是那么容易理解,并且明确地在代码中执行检查更清晰(因为您可以准确地报告错误 - “11月仅30天”,而不是“不匹配模式”消息,这是旁边无用)


This (from regexplib.com) will match what you want, and perform checks for leap years, days-per-month etc. It's a little more tolerant of separators than you want, but that can be easily fixed. As you can see, it's rather hideous.

Alternatively (and preferably in my opinion) you may want to simply check for figures in the correct places, and then perform leap year and days-per-month checks in code. Sometimes one regexp isn't so understandable and there's greater clarity in performing the checks in code explicitly (since you can report precisely what's wrong - "only 30 days in November", rather than a "doesn't match pattern" message, which is next to useless)

相关问答

更多
  • 您的问题的答案是,允许反向引用的“正则表达式”语言既不规则也不上下文。 (换句话说,正如你所指出的那样,你不能用普通语言和CFL来模拟反向引用。)事实上,维基百科说,我们在实践中使用的许多“正则表达式”语言都是NP-Complete : 在许多现代工具的支持下,与无限数量的后向引用进行模式匹配是NP完全的(参见定理6.2)。 正如其他人所建议的那样,计算机语言和库中普遍支持的正则表达式语言与正式语言理论中的正则表达式不同。 Larry Wall在Perl中写到 “正则表达式”, “正则表达式”与真正的正则表 ...
  • 您正在使用的Boost库提供了一种将重复的组捕获到堆栈中的方法, 前提是您使用BOOST_REGEX_MATCH_EXTRA标志集编译库,否则将没有名为captures的成员。 当你使用boost::regex_search或boost::regex_match ,传递boost::match_extra标志,你将使用你的(.)* (匹配并捕获任何字符但是换行符,零次或多次出现)捕获所有值(.)*通过sub_match对象的capture成员可访问的堆栈。 以下是官方Boost网站的演示方法: #inclu ...
  • 不,这很简单。 有限自动机(它是正则表达式的基础的数据结构)除了它的状态之外没有内存,如果你有任意深度的嵌套,则需要一个任意大的自动机,这与自动机的概念相冲突。 您可以将嵌套/配对元素匹配到一个固定的深度,其深度仅受您的内存限制,因为自动机变得非常大。 但实际上,您应该使用下推自动机,即无上下文语法的解析器,例如LL(自上而下)或LR(自下而上))。 您必须考虑更差的运行时行为:O(n ^ 3)与O(n),n =长度(输入)。 有许多解析器生成器可以使用,例如Java的ANTLR 。 找到Java(或C)的 ...
  • 如果你匹配HTML,你可能会匹配a标签中的href和a标签的内容。 uk@example1.com if you are matching HTML you are probably matching both the href in the a tag and the content of the a tag. uk@example1.com
  • 我会选择一个略有不同的正则表达式: ^Sep 12 09:23:(?:4[5-9]|50) 说明: [45-50]是一个匹配4的字符类, 5到5之间的所有字符和0 。 这是因为字符类是char-by-char。 对此的经典修复是通过数字前缀定义替代方案: (?:...)是一个用于节省一些资源的非记录组 4[5-9]匹配数字45 ,... 49 另一种选择是50 ,你的间隔的上限。 在这里演示。 您可以确保只编译一次正则表达式。 所以你的脚本使用更少的内存和CPU: import fileinput,re ...
  • 如果您传递给它的整个字符串是一个日期,您的RegEx似乎只会找到匹配项。 尝试删除^和$ 以下是使用RegEx重新编写的示例,它将以mm / dd / yyyy和mm-dd-yyyy格式查找日期 - Private Sub TestDate() MsgBox RegExDate("cancel on 12/21/2010 ") End Sub Private Function RegExDate(s As String) As String Dim re, match Set re ...
  • 这 (来自regexplib.com )将匹配你想要的,并执行闰年,每月每天等的检查。它比你想要的更容忍分隔符,但这可以很容易地修复。 如你所见,它相当可怕。 或者(最好在我看来)你可能只想检查正确位置的数字,然后在代码中执行闰年和每月每日检查。 有时一个正则表达式不是那么容易理解,并且明确地在代码中执行检查更清晰(因为您可以准确地报告错误 - “11月仅30天”,而不是“不匹配模式”消息,这是旁边无用) This (from regexplib.com) will match what you want, ...
  • 将字符串解析为DateTime并比较它们会不会更容易? Wouldn't it be easier to parse the strings to DateTimes and comparing those?
  • ^符号匹配字符串的开头, $匹配结束。 删除它们允许模式匹配字符串中的日期。 喜欢这个: "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d(?:,)" The ^ sign matches the start of the string and $ matches the end. Removing those allows the pattern to match dates within the string. Like ...
  • $result = preg_replace('/(?:[^,]*,){4}/', '\0\r\n', $subject); 这匹配一行中的四个逗号分隔值(我假设您不会在组内的字符串中使用逗号)并在它们之后添加一个CRLF。 [编辑]以上是基于PHP的解决方案 对于纯MySQL解决方案,请安装lib_mysqludf_preg并使用: SELECT preg_replace('/(?:[^,]*,){4}/', '${0}\r\n', `fieldname`) as 'new_layout' fr ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)