我必须每隔一两秒钟在屏幕上监控一些数据更新信息.我认为使用此实现的方式:
componentDidMount() {
this.timer = setInterval(()=> this.getItems(), 1000);
}
componentWillUnmount() {
this.timer = null;
}
getItems() {
fetch(this.getEndpoint('api url endpoint"))
.then(result => result.json())
.then(result => this.setState({ items: result }));
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
当我有关系时,我在试图找到查询猫鼬中某些内容的正确方法时遇到了一些困难。
基本上我有一个文档,其 ObjectId 与另一文档相关(如下所示)。
但是当我尝试过滤引用的属性时,没有任何效果了。基本上,问题是这一行“ .where({ "Recipe.Title": new RegExp("*") }) "
// const configs
const config = require('./config');
// mongodb setup
const mongoose = require('mongoose');
mongoose.connect(config.database);
var Schema = mongoose.Schema
// recipe schema
const RecipeSchema = mongoose.Schema({
Title: { type: String },
Description: { type: String },
Complaints: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Complaint' }],
});
const Recipe = mongoose.model('Recipe', RecipeSchema);
// complaint schema
const ComplaintSchema = mongoose.Schema({
Recipe : { type: mongoose.Schema.Types.ObjectId, ref: 'Recipe' },
Message: { type: String } …Run Code Online (Sandbox Code Playgroud) 我在C#中有这个代码:
string data = "something ... 1,000 anything 20,000 other thing...";
string pattern = @"[0-9]+([\,|\.][0-9]{1,})*([\.\,][0-9]{1,})?";
MatchCollection collection = Regex.Matches(data, pattern);
foreach (Match item in collection)
{
Console.WriteLine("{0} - {1} - {2}", item.Value, item.Index, item.Length);
}
Console.WriteLine();
Console.WriteLine("End!");
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
...我试图用C++(本机代码,没有.net程序集)转换它,所以我得到这样的东西:
void main()
{
string data = "something ... 1,000 anything 20,000 other thing...";
regex pattern("([0-9]+([\\,|\\.][0-9]{1,})*([\\.\\,][0-9]{1,})?)");
const sregex_token_iterator end;
for (sregex_token_iterator i(data.begin(), data.end(), pattern); i != end; ++i)
{
std::cout << i->str() << "-" << i->length() << std::endl;
}
cout << endl …Run Code Online (Sandbox Code Playgroud)