2014-08-28 72 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