|
首先确认一点,这个不是 FineUIMvc 的BUG,而是自己注册的 .Listener("afteredit", "onCalculate") 中处理的问题。
这个地方有点意思,我们来分析一下:
1. 在【含税单价】中输入数字 60,然后失去焦点,会触发 afteredit 事件:
2. 在 afteredit 中,判断 columnId == TaxPrice,会调用 updateCellValue 更新【单价】单元格的值:
3. 这是问题来了,调用updateCellValue 时同样会触发 afteredit 事件,此时 columnId == Price,此时计算的结果是 6.0001:
4. 由于【含税单价】值从 60 改为了 60.0001,所以会再次触发 afteredit 事件,只不过此时计算的【单价】和之前相同,所以不会再次触发 afteredit 事件了。
在整个过程中,修改一次 【含税单价】,其实 afteredit 事件触发了 3 次!!这应该是之前没想到的吧。如果每次改变的值都不同,这将会是一个死循环。
解决办法也很简单,用 F.noEvent 将对 updateCellValue 的调用包含起来:
- function onCalculate(event, value, params) {
- var me = this, columnId = params.columnId, rowId = params.rowId;
- var Price = me.getCellValue(rowId, 'Price');
- var TaxPrice = me.getCellValue(rowId, 'TaxPrice');
- if (columnId === 'Price') {
- TaxPrice = Price * (1 + 10 / 100);
- F.noEvent(function () {
- me.updateCellValue(rowId, 'TaxPrice', TaxPrice.toFixed(4));
- console.log("This is Price");
- });
- }
- if (columnId === 'TaxPrice') {
- Price = TaxPrice / (1 + 10 / 100);
- F.noEvent(function () {
- me.updateCellValue(rowId, 'Price', Price.toFixed(4));
- console.log("This is TaxPrice");
- });
- }
- }
复制代码
其实,官网示例已经有现成了例子:http://fineui.com/demo_mvc#/demo ... /UpdateCellValueTax
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|