English 中文(简体)
Knockout js:使新的投入名称具有独特性
原标题:Knockout js: making the new input name unique

我先与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>
问题回答




相关问题
how to get option title="sample" using jquery

I m trying to update a hidden field based on the a title attribute on a select option, I ve tried the code bellow and can t seem to get it to work. <form> <select id="selectbox"&...

这能否转化为多例(20+)的工作?

I m使用该代码进行粉碎。 您点击了 im,打开了盒子,在 im子上点击也关闭了箱子。 点击的成像交换器。 迄今为止,我一直未能将这一点转化为......。

finding clicked id deep in document using jquery

I m going to use the text from the jquery example, For example, consider the HTML: <lots of divs to get to here> <div id="#targetid_0"> Click here </div> <div id="#targetid_1"&...

Extracting numbers from the parent attribute in jQuery

By clicking on the "mylink" I want the link to be replaced by the number "123", which is extracted from parent tag. I think I m not doing the ".match(...." right. jQuery: $(document).ready(function()...

jquery string to function convert

is this possible? <div id="anything">I will change</div> <div id="id" jq="$( #anything ).css({background: red })"></div> var x = $( #id ).attr( jq ) ; jQuery.call(x); ...

热门标签