天数计算方法(使用ZK和MVVM)
Days Calculation Method (using ZK and MVVM)
好吧,好吧,如果有人感兴趣的话,我将把我对 ZK 框架和 MVVM 模式的所有疑虑一步一步地链接到一系列简单的问题上:
现在,在正确绑定所有数据后,我决定尝试一下表格的日期。所以我的想法是当我选择一个日期时,它会通过操作计算天数并将其显示在另一个文本框中,代码如下:
.zul 文件
<datebox id="" format="medium" onCreate="" value="@bind(vm.fechaIngreso)" width="100%"
onSelect="@command('calcularDias')" mold="rounded" readonly="true" constraint="no empty, no future"
disabled="@load(empty vm.camaPaciente)"/>
视图模型上的命令
@Command
@NotifyChange({"fechaIngreso"})
public void calcularDias(){
long milisegundosPorDia = 24 * 60 * 60 * 1000;
java.util.Date hoy = new Date();
long tmp = (hoy.getTime() - this.getFechaRegistro().getTime())/milisegundosPorDia;
this.setDiasEstancia((int)tmp);
}
where "hoy" = today date and getFechaRegistro = registration date, 它假设它必须计算另一个文本框中的天数,但它不起作用。也许是绑定问题或计算问题。我感谢任何解决我的问题的建议。非常感谢你。
我想你的文本框绑定到 diasEstancia
属性?然后
您应该让命令通知该值的更改:
@NotifyChange({"diasEstancia"})
您不使用 属性 fechaIngreso
(绑定到您的日期框)来计算日差,但您使用 this.getFechaRegistro()
这是据我从发布的代码中看到的那样没有改变。因此,diasEstancia
中的值永远不会改变(一天)。
好吧,好吧,如果有人感兴趣的话,我将把我对 ZK 框架和 MVVM 模式的所有疑虑一步一步地链接到一系列简单的问题上:
现在,在正确绑定所有数据后,我决定尝试一下表格的日期。所以我的想法是当我选择一个日期时,它会通过操作计算天数并将其显示在另一个文本框中,代码如下:
.zul 文件
<datebox id="" format="medium" onCreate="" value="@bind(vm.fechaIngreso)" width="100%"
onSelect="@command('calcularDias')" mold="rounded" readonly="true" constraint="no empty, no future"
disabled="@load(empty vm.camaPaciente)"/>
视图模型上的命令
@Command
@NotifyChange({"fechaIngreso"})
public void calcularDias(){
long milisegundosPorDia = 24 * 60 * 60 * 1000;
java.util.Date hoy = new Date();
long tmp = (hoy.getTime() - this.getFechaRegistro().getTime())/milisegundosPorDia;
this.setDiasEstancia((int)tmp);
}
where "hoy" = today date and getFechaRegistro = registration date, 它假设它必须计算另一个文本框中的天数,但它不起作用。也许是绑定问题或计算问题。我感谢任何解决我的问题的建议。非常感谢你。
我想你的文本框绑定到
diasEstancia
属性?然后 您应该让命令通知该值的更改:@NotifyChange({"diasEstancia"})
您不使用 属性
fechaIngreso
(绑定到您的日期框)来计算日差,但您使用this.getFechaRegistro()
这是据我从发布的代码中看到的那样没有改变。因此,diasEstancia
中的值永远不会改变(一天)。