【问题标题】:MobileFirst JSONStore working as intended on emulator, but failing on ios deviceMobileFirst JSONStore 在模拟器上按预期工作,但在 ios 设备上失败
【发布时间】: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


【解决方案1】:

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

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

ma​​in.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);
    });
}

【讨论】:

  • 我有一个 collection.js 作为初始化程序。它已附加到主帖,工作方式类似。我假设的问题在于 iOS 设备处理异步调用的方式?
猜你喜欢
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 2023-03-24
  • 1970-01-01
相关资源
最近更新 更多