从Rest服务devextreme读取动态JSON流

时间:2014-11-18 13:20:06

标签: javascript json rest

我正在使用Devextreme使用Visual Studio创建移动应用程序。

我们的Restful服务发送回JSON流,现在我无法解释它,很可能是因为数据是流式的。

这是我的db.js文件:

(function ($, DX) {
var dbImpl = {
   url: 'http://master/umbrellamobileservice.co.za/product/04',
    _sendRequest: function (type, params) {
        var deferred = new $.Deferred();
        var requestSettings = {
            url: $.trim(dbImpl.url),
            type: type,
            crossDomain: true,
            contentType: "application/jsonp; charset=utf-8",
            dataType: 'jsonp',
            async: false,
            jsonpCallback: 'jsonpCallback',
            success: function (data) {
                            deferred.resolve($.isArray(data) ? data : [data]);
            }
        };
        if (params) {
            if (type == 'DELETE') {
                if (requestSettings.url[requestSettings.url.length - 1] != '/')
                    requestSettings.url += '/';
                requestSettings.url += params.toString();
            }
            else
                requestSettings.data = params;
        }
        $.ajax(requestSettings);
        return deferred;
    },
    load: function (loadOptions) {


        if (loadOptions.refresh) {
            return dbImpl._sendRequest('GET');
        }
    },
    insert: function (params) {
        return dbImpl._sendRequest('POST', params);
    },
    update: function (params) {
        return dbImpl._sendRequest('PUT', params);
    },
    remove: function (params) {
        return dbImpl._sendRequest('DELETE', params);
    }
};
Restful_Ex_3.db = new DevExpress.data.CustomStore(dbImpl);
})(jQuery, DevExpress);

这是我的home.js文件:

Restful_Ex_3.home = function (params) {

var viewModel = {
    jsonp: true,
    dSource: new DevExpress.data.DataSource(Restful_Ex_3.db), //
};

return viewModel;
};

这是我的home.dxview文件:

<div data-options="dxView : { name: 'home', title: 'Home' } ">

<div data-bind="dxList: { dataSource: dSource }">
       <div data-options="dxTemplate : { name: 'item' } " >
           <span data-bind="text: product"></span>
         <!--  <span data-bind="text: Description"></span> -->
           <div data-bind="dxButton: {text: 'Edit', clickAction: function(e) { $root.btnEditClick($data.code, $data.product); }}"></div>
           <div data-bind="dxButton: {text: 'Delete', clickAction: function(e) {    $root.btnDeleteClick($data.code);}}"></div>
       </div>

   <div data-bind="dxTextBox: {}"></div>

    

服务返回的JSON流的格式如下:

{"product":[{"code":"04","description":"Umbrella Support","quantity":"-15.000000","uom":"EA","price":"470.000000"}]}

我只是想把它读到一个列表框,或者在这个阶段的任何东西。我无处可去。有人可以帮忙吗?

0 个答案:

没有答案