Ibm mobilefirst IBM Worklight JSONStore自动增量字段

Ibm mobilefirst IBM Worklight JSONStore自动增量字段,ibm-mobilefirst,auto-increment,jsonstore,Ibm Mobilefirst,Auto Increment,Jsonstore,我使用Worklight JSONStore,需要一个数字字段自动递增。 我试过这种方法,但不起作用 var COLLECTION_SPESE = { Spese : { searchFields: {id: "INTEGER primary key autoincrement", importo: "string", valuta: "string", metodoPagamento: "string", acconto

我使用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"}
    }
};

我该怎么做呢?

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

或者,您可以依赖于JSONStore生成的
\u id
的值。它是从
1
开始的自动递增整数。分配给
\u id
的值永远不会重复使用,例如,如果删除
\u 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'}}]
})
供参考-功能请求