gpt4 book ai didi

javascript - Knockoutjs 复杂绑定(bind)组合选择表

转载 作者:行者123 更新时间:2023-11-28 09:29:52 25 4
gpt4 key购买 nike

我有一个用于添加新预算详细信息的表格,如下图所示:

enter image description here

当我选择收入帐户时,另一行将添加到 View 模型集合中:

enter image description here

我想在添加新行时将所有字段值设置为“0.00”,我也遇到问题,因为如果我删除一行,则“更改"组合事件不存在,因此在更改最后一个组合时无法添加新行。

有什么线索吗?这是 fiddle 工作示例:http://jsfiddle.net/rLUyS/9/

这是我用来将更改操作绑定(bind)到最后添加的组合的代码:

$('select[name=cboincomeaccount_' + newRowIndex + ']').bind("change", {
combo: $(this)
}, handler);

function handler(event) {

newRowIndex++;
var combo = jQuery(this);
var row = combo.parent().parent();

appViewModel.addRow();

// Unbind
combo.unbind('change');
// Bind new combo
jQuery('select[name=cboincomeaccount_' + newRowIndex + ']').bind("change", {
combo: jQuery(this)
}, handler)

jQuery(row).find('input[name^="txtincmonth"]').removeAttr('disabled');
};

提前致谢!!

最佳答案

这可能不是 knockout 问题,而是用户界面问题。

I want to set all field values to "0.00" when the new row is added

嗯,这很简单。只需将可观察行初始化为全零即可。

When I select an Income Account then another row is added to the viewmodel collection... and also I have a problem because if I delete a row then the "change" event of the combo doesnt exist so there is no way to add a new row when changing the last combo.

这可能是一个可以协商的要求。

为什么不创建一个“添加”按钮,而不是坚持这种“漂亮”的行为,当用户在下拉列表中创建一个部分时添加一行?

此外,即使我们可以完成您所要求的任务(并且我可以设想一种我们可以做到这一点的方法),当需要将用户的输入保存到服务器时您会做什么?您打算忽略最后一个空行吗?

关于javascript - Knockoutjs 复杂绑定(bind)组合选择表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13851628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com