【发布时间】:2015-10-15 12:13:55
【问题描述】:
我有以下几行代码可以将一些变量添加到本地集合中:
var data = {
name: '123',
brand: '123',
model: '123',
img: 'imgurl',
category: '123',
segment: 'Recreational',
pilotFstName: '123',
pilotLstName: '123',
insuranceNumber: '123',
insNumber2: '123',
extras: '123',
hasCamera: '123',
insuranceDate: '123'
};
var collectionName = 'Drones';
var options = {};
WL.JSONStore.get(collectionName)
.add(data, options)
.then(function(numberOfDocumentsAdded) {
//handle success
alert("Done");
})
.fail(function(errorObject) {
//handle failure
alert(errorObject);
});
这在浏览器中运行良好,但在任何 iOS 物理设备中都失败并出现 INVALID_SEARCH_FIELD 错误。这是 Xcode 中的完整错误堆栈。
[JSONStoreCollection findWithQueryParts:andOptions:error:] in JSONStoreCollection.m:603 :: 错误:JSON_STORE_INVALID_SEARCH_FIELD, 代码:22,集合名称:Drones,访问者用户名:jsonstore, currentQuery: (null), JSONStoreQueryOptions: [JSONStoreQueryOptions: sort=( { identifier = desc; } ) filter=(null), limit=1, offset=(null)]
我的 Collections.js:
function getCollections(){
return {
Account : {
searchFields: {
userName:"string",
password:"string",
frstName:"string",
lstName:"string",
mail:"string"
}
},
Drones : {
searchFields: {
name:"string",
brand:"string",
model:"string",
img:"string",
category:"string",
segment:"string",
pilotFstName:"string",
pilotLstName:"string",
insuranceNumber:"string",
insNumber2:"string",
extras:"string",
hasCamera:"string",
insuranceDate:"string"
}
},
Historial : {
searchFields: {
name:"string",
date:"string",
posXStart:"string",
PosYStart:"string",
PosXFinish:"string",
PosYFinish:"string"
}
}
};
};
(function () {
WL.JSONStore.init(getCollections(), {
// password : 'PleaseChangeThisPassword'
})
.then(function () {
WL.Logger.debug(['All collections were loaded successfully'].join('\n'));
})
.fail(function (errObj) {
WL.Logger.ctx({pretty: true}).error(errObj);
});
}());
【问题讨论】:
-
还有更多错误吗? Xcode 控制台中的异常?
-
这是 xcode 中的完整错误堆栈。这不会在模拟器上发生:[JSONStoreCollection findWithQueryParts:andOptions:error:] in JSONStoreCollection.m:603 :: 错误:JSON_STORE_INVALID_SEARCH_FIELD,代码:22,集合名称:Drones,访问者用户名:jsonstore,currentQuery:(null), JSONStoreQueryOptions: [JSONStoreQueryOptions: sort=( { identifier = desc; } ) filter=(null), limit=1, offset=(null)]
-
您的 JSONStore 的 .init 在哪里?示例代码中缺少它。顺便说一句,代码 sn-p 失败了。
标签: ios ibm-mobilefirst jsonstore