如何将转换器和/或绑定表达式应用于表中的数据?



我在表中显示数据集。如何修改其中一个数据单元的绑定以使用转换器甚至绑定表达式?在属性编辑器中,我似乎只能从列表中选择单个单元格的绑定,而无法在文本框中编辑它们。

具体来说,我只需要在特定时区显示日期时间的一个时间部分,并且也许(还不确定(如果日期时间不是今天而是明天,也会使日期时间看起来不同。

格式化日期以仅显示时间:

@datasource.item.DateTime#formatDate('HH:mm:ss') // format: 13:30:30

对于时区问题,您不能只使用用户拥有的时区,这应该是应用制作工具的默认时区吗?使用此格式可在日期字段中查看时区:

@datasource.item.DateTime#formatDate('HH:mm:ss, zzzz') // format: 13:30:30, UTC+3

(更多格式选项在这里:http://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/DateTimeFormat.html(

对于不同日期的不同样式,我将对日期字段样式使用绑定表达式:

getDateStyles(@widget)

其中getDateStyles是这样的:

function getDateStyles(widget) {
var dateValue = widget.datasource.item.DateTime;
var today = new Date();
// setting the date to 00:00:00.00, don't know if there's a better way.
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
var tomorrow = today.addDays(1);
if (dateValue < tomorrow) {
return ["MyStyleForPreviousDays"];
}
else {
return ["MyStyleForFutureDays"];
}
}

我创建了addDays方法:

Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
};

希望这能回答你的一些问题,我可能没有完全理解。

相关内容

最新更新