我先与Knockout一道采取初步步骤。 j 采用(两个复杂)表格计算未付账单的账面,同时铭记部分付款、费用和合同处罚。
这一计算将在PHP中处理,因为在PHP中,当时在联合材料中,I m比较少。 Knockout正在处理增加新形式领域的动态,使甚至在最复杂的情况下使用的形式具有灵活性。
为了能够正确提取数据,我将通过邮局向PHP提供三个多维阵列:
- invoice[$i][name] / invoice[$i][amount] / invoice[$i][date] / ...
- payment[$j][name] / ...
- cost[$k][name] / ...
在联合材料中,我似乎无法解决的问题是,新的形式要素应当由Knockout.js产生,独一无二的数字应当与(一卷)相配。
data-bind="attr:{name: someFunctionToGiveUniqueName}"
I ve looked into the uniqueName-binding, but I need to have three uniqueNames and I should be able to customize the resulting name to keep the data structured.
This is my viewModel (and it works, except for the not-so-unique-naming-of-inputfields):
<script type="text/javascript">
// Overall viewmodel
function ViewModel() {
var self = this;
// Data
self.Hoofdsom = ko.observableArray();
self.Betaling = ko.observableArray();
self.Kost = ko.observableArray();
self.hsBeschr = ko.observable();
self.hsBedrag = ko.observable();
self.hsVerval = ko.observable();
self.hsIntr = ko.observable();
self.hsIntrType = ko.observable();
self.hsSchadeType = ko.observable();
self.hsSchadePerc = ko.observable(10);
self.hsSchadeMin = ko.observable(0);
self.hsSchadeMax = ko.observable(1500);
// Initial State
self.Hoofdsom.push("new");
// Operations
self.addHoofdsom = function() {
self.Hoofdsom.push(self.Hoofdsom().length);
}
self.remHoofdsom = function(hfd){
self.Hoofdsom.remove(hfd);
}
self.addBetaling = function() {
self.Betaling.push(self.Betaling().length);
}
self.remBetaling = function(bet){
self.Betaling.remove(bet);
}
self.addKost = function() {
self.Kost.push(self.Kost().length);
}
self.remKost = function(kos){
self.Kost.remove(kos);
}
}
// Apply bindings
ko.applyBindings(new ViewModel());
</script>