RxDB:indexedDB的踩坑之路目前国内社区关于RxDB的资料很少。本文是记录其使用中遇到的一些问题总结,不会涉及科普基础知识,有兴趣的同学请另写一篇。在Schema//Demo示例中实现默认生成器?,这是一个Schema定义constSchema={"title":"heroschema","version":0,"description":"describesasimplehero","type":"对象","属性":{"名称":{"类型":"字符串","默认":函数(){返回'idGenerate'+Math.random().toString(16).substr(2,12)}}},"required":["color"]}在RxDB中,Schema在设计之初应该是一个纯JSON,可以一直解析和字符串化,所以不支持函数,但是这样做的好处有很多,比如……那么如果我们想实现一个像上面那样的默认值生成器,我们应该怎么做呢?那是!使用Middleware-hooks添加hooks,例如://Implementationexample?myCollection.preInsert(function(documentData){if(!documentData.name){documentData.name='idGenerate'+Math.random().toString(16).substr(2,12)}},false);参考链接:RxDB-Middlewaresortsort排序只能在有索引的字段上排序,也可以创建复合索引compoundIndex。//这也是一个Schema{"title":"heroschema","version":0,"description":"描述一个简单的英雄","type":"object","properties":{"name":{“type”:“string”,“index”:true},“age”:{“type”:number},“create_time”:{“type”:number}},“compoundIndex”:[[“age","create_time"]]}先这样吧,想到什么就写什么
