How to avoid duplicate entries in IBM JSONStore

允我心安 提交于 2019-12-25 01:46:17

问题


WL.JSONStore.get(collectionName).change(data, options) method does not seem to work for duplicate values. I get duplicate values entered whenever data is loaded through the adapter. Below is the code that I have used to avoid duplicate entries.

init(){
console.log('JSONStore init function callled');
let collections = {
  activities: {
    searchField: {serialKey: 'string'},
    adapter: {
      name: 'ServiceAdapter',
      add: 'pushActivities',
      remove: 'removeActivity',
      replace: 'replaceActivity',
      load: {
          procedure: 'getActivities',
          params: [],
          key: 'rows'
      }
  }
  }
}
WL.JSONStore.init(collections).then((success) => {
  console.log('-->JSONStore init success')
}, (failure) => {
  console.log('-->JSONStore init failed', failure)
})
}

load() {
let dataRequest = new 
WLResourceRequest("/adapters/ServiceAdapter/getActivities", 
WLResourceRequest.GET);
dataRequest.send().then(
(response) => {
this.data = response.responseJSON.rows;
this.activityService.put(this.data);
})
}

put(data){
console.log('--> JSONStore put function called');
let collectionName = 'activities';
let options = {
  replaceCriteria: ['serialKey'],
  addNew: true,
  markDirty: false
};
WL.JSONStore.get(collectionName).change(data, options).then((success) => {
  console.log('--> JSONStore put success')
}, (failure) => {
  console.log('--> JSONStore put failed', failure)
})
}

Adapter Function:

function getActivities() {
var path = 'employees' + '/_all_docs?include_docs=true';
var input = {
    method : 'get',
    returnedContentType : 'json',
    path : path,
};
var response = MFP.Server.invokeHttp(input);
if (!response.rows) {
    response.isSuccessful = false;
    return response;
} else {
    var results = [];
    for (var i=0; i < response.rows.length; i++) {
        results.push(response.rows[i].doc);
    }
    return {'rows': results};
}
}       

I have even tried by:

searchFields: {serialKey: 'string',serialId: 'string'}
replaceCriteria: ['serialKey','serialId']

But no luck. NOTE: There is no error in the former one, whereas the later results in an error.

ERROR : PROVISION_TABLE_SEARCH_FIELDS_MISMATCH (I have already tried to destroy the collection and perform the change, as the link suggests.

I have followed the below link:

https://www.youtube.com/watch?v=Ep6w1zXoI-k

I am using the below versions: mfpdev : 8.0.0-2017102406

Let me know if you need any more details.

来源:https://stackoverflow.com/questions/47489647/how-to-avoid-duplicate-entries-in-ibm-jsonstore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!