Reputation: 25
Init the JSON Store in JavaScript:
function doJSTestInit() {
var peopleCollectionName = 'people';
var collections = {
// Object that defines the 'people' collection.
people : {
// Object that defines the Search Fields for the 'people'
// collection.
searchFields : {
mid1 : 'integer', //模块/模块组主键ID
level : 'integer', //组件层级
moduleId : 'string', //模块/模块组业务ID
appId : 'integer', //应用ID
moduleType : 'string', //功能模块F,登陆模块
// status : 'string', //模块状态 上架: U 下架: D 暂停:P
// moduleName : 'string', //模块/模块组名称
// iconUrl : 'string', //图标URL
// updateStatus : 'string', //强制更新,提示更新
// downloadStatus : 'string', //必选下载,可选下载
// engineType : 'string', //模块类别 EMP WL
// pauseReason : 'string', //暂停原因
// moduleUrl : 'string', //模块存放路径UR
// md5 : 'string', //模块资源包MD5码
// needLogin : 'string', //是否需要登录才能使用模块功能,是 : Y, 否 : N
}
},
};
WL.JSONStore.destroy()
.then(function() {
// Open the collection
return WL.JSONStore.init(collections);
}).then(function() {
// Data to add, you probably want to get
// this data from a network call (e.g. Worklight Adapter).
var data = [ {
name : 'carlos',
age : 10
} ];
// Optional options for add.
var addOptions = {
// Mark data as dirty (true = yes, false = no), default true.
markDirty : true
};
// Get an accessor to the people collection and add data.
return WL.JSONStore.get(peopleCollectionName).add(data, addOptions);
});
}
then try to open this JSON Store in iOS Native Code:
-(void)onActionReceived:(NSString *)action withData:(NSDictionary *)data{
NSLog(@"LoginScreenViewController :: onActonReceived :: %@", action);
if ([action isEqualToString:@"testJSONInit"]){
NSError* error = nil;
// [[JSONStore sharedInstance]destroyDataAndReturnError:&error];
people = [[JSONStoreCollection alloc]initWithName:@"people"];
[people setSearchField:@"mid1" withType:JSONStore_Integer]; //模块/模块组主键ID
[people setSearchField:@"level" withType:JSONStore_Integer]; //组件层级
[people setSearchField:@"moduleId" withType:JSONStore_String]; //模块/模块组业务ID
[people setSearchField:@"appId" withType:JSONStore_Integer]; //应用ID
[people setSearchField:@"moduleType" withType:JSONStore_String]; //功能模块F,登陆模块
// [people setSearchField:@"status" withType:JSONStore_String]; //模块状态 上架: U 下架: D 暂停:P
// [people setSearchField:@"moduleName" withType:JSONStore_String]; //模块/模块组名称
// [people setSearchField:@"iconUrl" withType:JSONStore_String]; //图标URL
// [people setSearchField:@"updateStatus" withType:JSONStore_String]; //强制更新,提示更新
// [people setSearchField:@"downloadStatus" withType:JSONStore_String]; //必选下载,可选下载
// [people setSearchField:@"engineType" withType:JSONStore_String]; //模块类别 EMP WL
// [people setSearchField:@"pauseReason" withType:JSONStore_String]; //暂停原因
// [people setSearchField:@"moduleUrl" withType:JSONStore_String]; //模块存放路径UR
// [people setSearchField:@"md5" withType:JSONStore_String]; //模块资源包MD5码
// [people setSearchField:@"needLogin" withType:JSONStore_String]; //是否需要登录才能使用模块功能,是 : Y, 否 : N
//Open the collections.
[[JSONStore sharedInstance] openCollections:@[people] withOptions:nil error:nil];
}else if ([action isEqualToString:@"testJSON"]){
int dataAddedToThePeopleCollection = [[people addData:@[@{@"moduleId" : @"carlos", @"level" : @20}] andMarkDirty:YES withOptions:nil error:nil] intValue];
}
}
Error will be caught below:
2014-10-20 20:37:57.517 JStoreTest[64745:879970] [ERROR] [JSONSTORE] -[JSONStore _provisionCollection:withSearchFields:withAdditionalSearchFields:withUsername:withPassword:withDropFirst:error:] in JSONStore.m:724 :: Error: JSON_STORE_EXCEPTION, code: -2, username: jsonstore, accessor username: jsonstore, collection name: people, searchFields: { appId = integer; level = integer; mid1 = integer; moduleId = string; moduleType = string; }, additionalSearchFields: { }
code: -2 means , PROVISION_TABLE_SEARCH_FIELDS_MISMATCH
But the fields are exactly match. If I use only 3 fields, it works perfectly, if more than 3 fields, above error appears. why? is this a bug? thanks.
Upvotes: 0
Views: 207
Reputation: 25
This doesn't directly address your issue, but I wanted to add that after you initialize in Javascript, you don't have to call openCollection() again in native; you can just call [[JSONStore sharedInstance] getCollectionWithName:@"people"]; and it will return the collection that was already initialized by Javascript. – Daniel A. González
Upvotes: 1
Reputation: 301
Hmm well it looks to me like you that you are trying to modify the search fields in native ios after you created them in js. You cannot do this even if you are just reinitializing the search fields. Try destroying the collection in the native iOS and then reinitializing the search fields.
Upvotes: 0