【问题标题】:Datasource not returning data from onSuccess function数据源未从 onSuccess 函数返回数据
【发布时间】:2015-03-12 17:09:39
【问题描述】:

当我通过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>

【问题讨论】:

    标签: knockout.js devexpress phonejs


    【解决方案1】:

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

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

    我也会使用 map 的 dataSource 函数而不是手动映射(参见 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
            }
        }
    });
    

    【讨论】:

    • 呃,我花了很长时间浏览 14.2 的文档,但我从未想过查看加载选项(刷新是在 v13 中)。再次感谢,一切正常,答案标记为正确。
    猜你喜欢
    • 2012-12-14
    • 2019-07-12
    • 1970-01-01
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    相关资源
    最近更新 更多