带多个过滤器的领域JS addListener

时间:2020-04-11 08:30:18

标签: realm

在这里,我有多个基于用户选择的任务项过滤器。但是addListener无法正常工作。添加/编辑任何任务后,仍然仅显示旧的初始过滤器值。

useEffect(() => {
    console.log('task useEffect');
    getTaskDetails('Today');
    taskResults.addListener(listener);
    return () => {
      taskResults.removeListener(listener);
    };
  }, []);


switch (value) {
  case TasksTypeEnum.Today:
    taskResults = realm.objects<TaskSchema>(TaskSchema.schema.name)
      .sorted('dueDate')
      .filtered(
        'dueDate >= $0 AND dueDate <= $1',
        startOfDay(new Date()),
        endOfDay(new Date()),
      );
    console.log(taskResults.length);
    // updateUI(taskResults);
    break;
  case TasksTypeEnum.Completed7Days:
    taskResults = realm.objects<TaskSchema>(TaskSchema.schema.name).sorted('dueDate').filtered('done = true');
    // updateUI(taskResults);
    break;
  case TasksTypeEnum.AllOverdue:
    taskResults = realm.objects<TaskSchema>(TaskSchema.schema.name)
      .sorted('dueDate')
      .filtered('done = false');
    // .filtered('dueDate <= $0 AND done = false', startOfDay(new Date()));
    // updateUI(taskResults);
    break;
  default:
    break;
}

0 个答案:

没有答案