【问题标题】:IBM Worklight JSONStore Auto-increment fieldIBM Worklight JSONStore 自动增量字段
【发布时间】:2014-10-22 09:53:21
【问题描述】:

我使用 Worklight JSONStore,我需要一个数字字段自动增量。 我尝试过这种方式,但没有奏效。

var COLLECTION_SPESE = {
    Spese : {
        searchFields:
            {id: "INTEGER primary key autoincrement", importo: "string", valuta: "string", metodoPagamento: "string", 
            acconto: "string", data: "string", motivazione: "string", categoria: "string", 
            icona: "string", checked: "boolean"}
    }
};

我该怎么办?

【问题讨论】:

    标签: ibm-mobilefirst auto-increment jsonstore


    【解决方案1】:

    您必须提供代码来自己进行自动递增。例如WL.JSONStore.get('collection').add({id: getLastId() + 1, ...})getLastId() 函数将返回集合中使用的最后一个 id 值。您必须为 getLastId 函数编写实现。 id 的搜索字段类型为 integer

    或者,您可以依赖 JSONStore 生成的 _id 的值。它是一个从1 开始的自动递增整数。分配给_id 的值永远不会重复使用,例如,如果您删除带有_id == 1 的文档,然后添加一个新文档,则1 不会再次用于新文档。

    WL.JSONStore.get('collection').add({name: 'carlos})
    .then(function () {
      return WL.JSONStore.get('collection').findAll();
    })
    .then(function (res) {
      //res => [{_id: 1, json: {name: 'carlos'}}]
    })
    

    仅供参考 - 功能请求here

    【讨论】:

      猜你喜欢
      • 2013-08-13
      • 2014-08-10
      • 2015-02-16
      • 2014-01-08
      • 2014-08-07
      • 2013-12-27
      • 2015-06-07
      • 2013-07-18
      • 1970-01-01
      相关资源
      最近更新 更多