当我通过mapped
将调试器粘贴到deferred.resolve(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>
答案 0 :(得分:1)
几乎所有内容都是正确的,只需删除if (loadOptions.refresh)
方法中的条件load
即可。
loadOptions
的字段
我还会使用dataSource的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
}
}
});