小编Edu*_*aki的帖子

每隔x秒轮询api并做出反应

我必须每隔一两秒钟在屏幕上监控一些数据更新信息.我认为使用此实现的方式:

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)

这是正确的方法吗?

polling reactjs

29
推荐指数
4
解决办法
2万
查看次数

按猫鼬中引用的属性过滤

当我有关系时,我在试图找到查询猫鼬中某些内容的正确方法时遇到了一些困难。

基本上我有一个文档,其 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)

mongoose mongodb

1
推荐指数
1
解决办法
7569
查看次数

如何将C#中的正则表达式代码转换为c ++

我在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)

c c# c++

0
推荐指数
1
解决办法
953
查看次数

标签 统计

c ×1

c# ×1

c++ ×1

mongodb ×1

mongoose ×1

polling ×1

reactjs ×1