2014-08-28 70 views
0

我使用Worklight JSONStore,我需要一个数字字段自动增量。 我试过这种方式,但没有奏效。IBM 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"} 
    } 
}; 

我该怎么办?

回答

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