Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
Session 如何在meteor中将regex发送到服务器端_Session_Meteor_Session Variables_Meteorite - Fatal编程技术网

Session 如何在meteor中将regex发送到服务器端

Session 如何在meteor中将regex发送到服务器端,session,meteor,session-variables,meteorite,Session,Meteor,Session Variables,Meteorite,在我的应用程序中,我正在构建一个查询对象,如下所示 Object {pointType: /analog/i, _id: Object} Object {pointType: Object, _id: Object} 我试图将其存储在会话变量中 Session.set("currentPointsQueryObject",queryObj); 然后点击事件,我得到这个对象 var res= Session.get("currentPointsQueryObject"); conso

在我的应用程序中,我正在构建一个查询对象,如下所示

Object {pointType: /analog/i, _id: Object}
Object {pointType: Object, _id: Object}
我试图将其存储在会话变量中

Session.set("currentPointsQueryObject",queryObj);
然后点击事件,我得到这个对象

  var res= Session.get("currentPointsQueryObject");
  console.log(res);
但在这里,我变得像下面

Object {pointType: /analog/i, _id: Object}
Object {pointType: Object, _id: Object}
同时,我将组id发送到服务器 通过从会话变量获取它,如

var group_id=Session.get("currentGroupId");
工作正常(正在服务器日志中显示id)

然后,我尝试将其存储在全局变量中,并按预期返回

如下面的点击事件

Object {pointType: /analog/i, _id: Object}
但当我将其发送到服务器端方法时(console.log()后面的立即行)

当我在服务器控制台中登录
res
时,它会显示

{ pointType: {}, _id: { '$nin': [] } }
尽管我在
pointType
中有一些内容,但它不会传递给服务器


任何人都知道,这是与存储相关的东西吗?

/code>/analog/i是正则表达式,对吗?存储在会话中的值和发送到方法的值必须是值的一部分。正则表达式不是。您不能直接将RegExp序列化为EJSON,但可以:

var regexp = /^[0-9]+$/;
var serialized = regexp.source;
发送已序列化的
,然后反序列化:

new RegExp(serialized)

看看:

从2015年起,有一种简便的方法可以教EJSON如何序列化/解析正则表达式(RegExp),在这个问题中有记录:


基本上,我们可以扩展RegExp对象类,并使用
EJSON.addType
将序列化传授给客户机和服务器。希望这能帮助宇宙中的某个人。:)

只需通过
.toString()
将RegExp字符串化,将其发送到服务器,然后将其解析回RegExp。

是的,没错。您知道将正则表达式发送到服务器端的任何方法吗?没有提供如何正确执行的答案