【问题标题】:LokiJS not allowing Json data to insertLokiJS 不允许插入 Json 数据
【发布时间】:2015-12-02 11:39:50
【问题描述】:

您好,我在以 json 格式在 db 中插入记录时正在使用 cordova/angularjs/lokijs,它显示类型错误(“文档需要是一个对象”),但如果是简单数组,它可以正常工作。我需要存储为 JSON作为要求。 任何帮助家伙 谢谢

【问题讨论】:

    标签: javascript angularjs javascript-objects visual-studio-cordova


    【解决方案1】:

    查看 LokiJS 的insert 代码:

          var docs = Array.isArray(doc) ? doc : [doc];
          var results = [];
          docs.forEach(function (d) {
            if (typeof d !== 'object') {
              throw new TypeError('Document needs to be an object');
            }
    

    其中doc 是传递给insert 方法的原始对象,如果doc 不是对象,LokiJS 将抛出错误。确保您传递给 insert 的参数是一个 JS 对象,typeof 语句应该确认这一点。

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2011-07-24
      • 2020-02-07
      相关资源
      最近更新 更多