我有一个$text-Index和这样的元素的mongodb :
{
foo: "my super cool item"
}
{
foo: "your not so cool item"
}
Run Code Online (Sandbox Code Playgroud)
如果我搜索
mycoll.find({ $text: { $search: "super"} })
Run Code Online (Sandbox Code Playgroud)
我得到第一项(正确).
但我也想用"uper"搜索获得第一项 - 但如果我尝试:
mycoll.find({ $text: { $search: "uper"} })
Run Code Online (Sandbox Code Playgroud)
我没有得到任何结果.
我的问题:如果有一种方法可以使用$ text,那么它会找到搜索字符串的一部分?(例如像'%uper%'在mysql)
注意:我不要求只进行正则表达式搜索 - 我要求在$ text-search中进行正则表达式搜索!
HTML:
<div>
<button data-id="3">Click Me</button>
</div>
Run Code Online (Sandbox Code Playgroud)
在经典的jQuery中,我会这样做:
$("div").on("click","button", test);
function test(){
alert($(this).data("id"));
}
Run Code Online (Sandbox Code Playgroud)
获取data-id被点击的元素
在TypeScript(在类中)我使用:
class foo { ...
$("div").on("click", "button", (event) => this.test());
public test(){
alert($(this).data("id")); // "undefined"
console.log($(this));
}
....
}
Run Code Online (Sandbox Code Playgroud)
在这里,我没有得到被点击的元素 - $(this)是类的实例.
我做错了什么?
我如何检查var是否是Nodejs中的可读流?
例:
function foo(streamobj){
if(streamobj != readablestream){
// Error: no writable stream
}else{
// So something with streamobj
}
}
Run Code Online (Sandbox Code Playgroud)
我试过了
if (!(streamobj instanceof stream.Readable)){
Run Code Online (Sandbox Code Playgroud)
但是我得到一个ReferenceError:没有定义流
在nodejs中,服务器(传入的http请求)的默认超时为 120000(2分钟)(参见:http://nodejs.org/api/http.html#http_server_timeout)
但是,如果我在docs 中的nodejs(http.request)中执行http请求,我只会找到一个函数(http://nodejs.org/api/http.html#http_request_settimeout_timeout_callback)来手动设置超时.
任何人都知道nodejs中的http请求是否有默认超时?或者nodejs尝试发送http请求没有结束?
我目前正在使用默认的“材料设计图标”构建一个 vuetifyjs-app。在生产版本中,我只使用了这种字体的 2 个图标(由 vuetify-component 芯片使用)。
按照建议,我包含了完整的 iconfont
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@3.x/css/materialdesignicons.min.css" rel="stylesheet">
但是生产构建这迫使用户仅为 2 个图标下载近 0.5MB 的数据。有没有什么办法:
我有一个非常严重的问题:
var cat = [ { slug: "test/foo", id: 1}, { slug: "test/bar", id: 1}];
var searchreg = new RegExp("test","g");
cat.forEach(function(item){
if(searchreg.test(item.slug)){
console.log(item);
}
});
Run Code Online (Sandbox Code Playgroud)
这应该打印出"cat"中的两个项目.但我只得到了第一个.如果我添加更多项目,我只会获得第二个(从第一个开始).
我得知它:
var cat = [ { slug: "test/foo", id: 1}, { slug: "test/bar", id: 1}];
cat.forEach(function(item){
var searchreg = new RegExp("test","g");
if(searchreg.test(item.slug)){
console.log(item);
}
});
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么这不起作用(Chrome) - 任何人都有想法?
javascript ×2
node.js ×2
jquery ×1
mongodb ×1
regex ×1
typescript ×1
vue.js ×1
vuetify.js ×1
wildcard ×1