Ibm mobilefirst 如何从SqlDataAdapter中提取数据并将其存储在MobileFirst中的JsonStore集合中

Ibm mobilefirst 如何从SqlDataAdapter中提取数据并将其存储在MobileFirst中的JsonStore集合中,ibm-mobilefirst,jsonstore,Ibm Mobilefirst,Jsonstore,我有一个SqlDataAdapter,我想将它存储在MobileFirst中的JsonStore集合中,并以表格形式显示它。我尝试过使用Load()方法,但它不起作用。 这是我的resultSetCollection.js文件 ;(function () { WL.JSONStore.init({ resultSet : { searchFields: {"EMP_NAME":"string","EMP_ID":"integer"} } }, { //

我有一个
SqlDataAdapter
,我想将它存储在MobileFirst中的JsonStore集合中,并以表格形式显示它。我尝试过使用
Load()
方法,但它不起作用。 这是我的resultSetCollection.js文件

;(function () {

WL.JSONStore.init({
    resultSet : {
        searchFields: {"EMP_NAME":"string","EMP_ID":"integer"}
    }
}, {
    // password : 'PleaseChangeThisPassword'
})

.then(function () {

     return WL.Client.invokeProcedure({
          adapter : 'EmployeeList',
          procedure : 'getEmployeeLists',
          parameters : []
        }); 
})
.then(function (responseFromAdapter) {

     alert('responseFromAdapter:' + JSON.stringify(responseFromAdapter.invocationResult.resultSet));
     var accessor = WL.JSONStore.get('resultSet');
     var data=responseFromAdapter.invocationResult.resultSet;
     var changeOptions = {
                replaceCriteria : ['EMP_ID', 'EMP_NAME'],
                addNew : true,
                markDirty : false
              };

    return accessor.change(data, changeOptions);
})
.then(function (response) {
    console.log(response);
    //Here I want to retrieve the collection and display it in a table
})
.fail(function (errObj) {
    WL.Logger.ctx({pretty: true}).error(errObj);
});

}())

来自客户端应用程序的适配器过程请求在其成功和失败回调中将有一个响应对象。因此,让我们假设请求成功,并且数据从后端服务器返回

我们还假设您已经初始化了一个JSONStore,并正确地设置了一个集合。然后,您只需要获取集合并向其中添加数据

下面的示例从HTTP适配器请求获取完整响应,并将其按原样放入集合中。当然,您需要为您的特定场景创建更好的设置

请注意,代码未经过优化,性能或逻辑未达到100%正确。这只是一个演示流程

在MauliLe1.1平台基础上测试7.0.0.00。 main.js:

var collectionName = 'mydata';
var collections = {
    mydata : {
        searchFields : {data: 'string'},
    }
};

function wlCommonInit(){
    WL.JSONStore.init(collections).then(
        function() {
            var resourceRequest = new WLResourceRequest("/adapters/myadapter/getStories", WLResourceRequest.GET);
            resourceRequest.send().then(resourceRequestSuccess, resourceRequestFailure);
        }
    );  
}

function resourceRequestSuccess(response) {
    WL.JSONStore.get(collectionName).add(response).then(
        function(){
            WL.Logger.info("successfully added response to collection");
            displayDataFromCollection();
        }, 
        function() {
            alert("failed adding response to collection");
        }
    );
}

function resourceRequestFailure() {
    alert ("failure");
}
如果您想从JSONStore中获取数据并将其显示在HTML中,可以执行以下操作:

// get a specific item from the stored response and display it in a table
function displayDataFromCollection() {
    WL.JSONStore.get(collectionName).findAll().then(
        function(result) {
            $("#mytable").append("<tr><td>" + result[0].json.responseJSON.rss.channel.title + "</td></tr>");
        }, 
        function() {
            alert ("unable to display collection");
        }
    );
}
<table id="mytable">
</table>
//从存储的响应中获取特定项并将其显示在表中
函数displayDataFromCollection(){
WL.JSONStore.get(collectionName.findAll()。然后(
功能(结果){
$(“#mytable”).append(“+result[0].json.responseJSON.rss.channel.title+”);
}, 
函数(){
警报(“无法显示集合”);
}
);
}
index.html如下所示:

// get a specific item from the stored response and display it in a table
function displayDataFromCollection() {
    WL.JSONStore.get(collectionName).findAll().then(
        function(result) {
            $("#mytable").append("<tr><td>" + result[0].json.responseJSON.rss.channel.title + "</td></tr>");
        }, 
        function() {
            alert ("unable to display collection");
        }
    );
}
<table id="mytable">
</table>


给我们看一些代码!!如果你什么都不给我们看,我们到底该怎么帮助你呢!?!??!?!?我们无法阅读您的屏幕,也无法理解您的想法。您必须向我们展示您拥有的内容,并解释您正在做的事情和不起作用的事情。如何以表格格式显示此集合,以及如果我要调用Sql适配器而不是Http适配器,该怎么办?您不将集合放在表中,而是将响应显示在表中。您需要从集合内部获取数据-此数据、适配器的响应。。。是一个JSON对象,因此您只需选择要显示的特定数据,并使用普通的JavaScript将其附加到HTML中所需的元素。找时间学习JavaScript并阅读JSONStore文档。@HyderAli,如果这个答案对您有帮助,请标记为已回答。