我试图在MongoDB查询的Meteor会话中保存正则表达式作为RegExp对象,但在Session.get()之后,RegExp对象只是一个空对象。流星:将RegExp对象保存到会话
JS
if (Meteor.isClient) {
Meteor.startup(function() {
var obj = {};
obj['regexp'] = new RegExp("test");
console.log("setting regular expression: " + obj['regexp']);
Session.set("test", obj);
});
Template.test.events({
'click button': function() {
var regex = Session.get("test");
console.log("now it is: ");
console.log(regex['regexp']);
}
});
}
if (Meteor.isServer) {
}
HTML
<head>
<title>meteor-regexp-session-test</title>
</head>
<body>
{{> test}}
</body>
<template name="test">
<button>hit the button and look at the console</button>
</template>
为什么这是行不通的任何想法?
预先感谢!
哇谢谢。不知道会话使用EJSON反序列化。另一个反应性数据源可能是本地Collection(myQuery = new Meteor.Collection(null))。或者我可以使用[$ regex操作符](http://docs.mongodb.org/manual/reference/operator/query/regex/),这样我就可以将查询保存为字符串。我喜欢eventedmind视频 - 可能会解决它。 – kerosene 2014-08-28 09:55:00