MobileFirst JSONStore在模拟器上按预期工作,但在ios设备上失败

时间:2015-07-24 18:04:52

标签: ios ibm-mobilefirst jsonstore

我有以下代码行将一些变量添加到本地集合中:

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,集合名称:无人机,访问者用户名: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);
    });

}()); 

1 个答案:

答案 0 :(得分:0)

我必须创建该集合,因为您没有在代码段中提及它 我还必须首先初始化JSONStore。

以下代码在浏览器和iOS模拟器中都适用于我(在大多数情况下,这也意味着在物理设备上也是如此):

<强> main.js:

var collectionName = 'myCollectionObject';

var collections = {
    myCollectionObject : {
        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'
        }
    }
};

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 options = {};
var addOptions = { };

function wlCommonInit(){
    WL.JSONStore.init(collections, options)

    .then(function () {
      return WL.JSONStore.get(collectionName).add(data, addOptions);
    })

    .then(function (numberOfDocumentsAdded) {
      alert ("success: " + numberOfDocumentsAdded);
    })

    .fail(function (errorObject) {
        alert ("failure: " + errorObject);
    });
}