繁体   English   中英

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

[英]MobileFirst JSONStore working as intended on emulator, but failing on ios device

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

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.m:603中的[JSONStoreCollection findWithQueryParts:andOptions:error:]:错误:JSON_STORE_INVALID_SEARCH_FIELD,代码:22,集合名称:无人机,访问者用户名:jsonstore,currentQuery :(空),JSONStoreQueryOptions:[JSONStoreQueryOptions:sort =({标识符= 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);
    });

}()); 

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

以下代码在浏览器和iOS Simulator中都对我有效(在大多数情况下,这在物理设备上也是如此):

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);
    });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM