数据源不从 onSuccess 函数返回数据

Datasource not returning data from onSuccess function

当我按 deferred.resolve(mapped); 将调试器固定在 mapped 上时,我从该数据源中获取了 100 个对象的数组。但是它没有将其传输到我的 dxTileView 中。

这真的不应该是一个有约束力的问题,因为它显示的是 noDataText 而不是错误。

有人知道我哪里出错了吗?

var dataSource = new DevExpress.data.DataSource({
        load: function (loadOptions) {
            if (loadOptions.refresh) {
                var deferred = new $.Deferred();
                callService("LoadEmployees", {
                    device: lStorage.getDeviceID()
                }, function (result) {
                    serverActive = true;
                    var mapped = $.map(result, function (data) {
                        return {
                            info: '',
                            id: data.EmployeeNo,
                            name: data.Name,
                            widthRatio: 2,
                            status: data.Status,
                            lastProject: data.LastProject,
                            lastStart: data.LastStart,
                            lastCostCenter: data.LastCostCenter,
                            lastScan: data.LastScan,
                            projectName: data.LastProject ? data.LastProject.Name : null,
                            inBreak: data.Status == 2,
                            working: data.Status == 1,
                            notWorking: data.Status == 0,
                            aktivProjectId: null
                        }
                    });
                    deferred.resolve(mapped);
                });
                return deferred.promise();
            }
        },
    });

html 在这里:

<div id="mitarbeiter" data-bind="dxTileView: {
           noDataText:noDataText, 
           height:tileWidgetHeight,
           itemClickAction:tileClick,
           baseItemHeight: 80, 
           baseItemWidth: 100,
           dataSource:dataSource, 
           showScrollbar: showScrollbar
      }">

    <div data-options="dxTemplate : { name: 'item' } " data-bind="css: {working:working,inBreak:inBreak}" class="tile">
      <h2 data-bind="text: name"></h2>
      <p data-bind="text: projectName"></p>
    </div>
  </div>

几乎一切都正确,只需删除load方法中的条件if (loadOptions.refresh)即可。

查看文档中 loadOptions 的字段 http://js.devexpress.com/Documentation/ApiReference/Data_Library/CustomStore/Configuration/?version=14_2#load

我还会使用数据源的 map 函数而不是手动映射(参见 example

var dataSource = new DevExpress.data.DataSource({
    load: function (loadOptions) {
        var deferred = new $.Deferred();

        callService("LoadEmployees", {
            device: lStorage.getDeviceID()
        }, function (result) {
            serverActive = true;
            deferred.resolve(result);
        });

        return deferred.promise();
    },
    map: function(data) {
        return {
            info: '',
            id: data.EmployeeNo,
            name: data.Name,
            widthRatio: 2,
            status: data.Status,
            lastProject: data.LastProject,
            lastStart: data.LastStart,
            lastCostCenter: data.LastCostCenter,
            lastScan: data.LastScan,
            projectName: data.LastProject ? data.LastProject.Name : null,
            inBreak: data.Status == 2,
            working: data.Status == 1,
            notWorking: data.Status == 0,
            aktivProjectId: null
        }
    }
});