首页 \ 问答 \ 根据动态添加的字段计算值(Calculating values based on dynamically added fields)

根据动态添加的字段计算值(Calculating values based on dynamically added fields)

我正在尝试基于字段创建动态聚合。 唯一的区别是它不是一个表格而是一个div区块。

我正在努力完成的

在按钮上单击添加字段,模板中的内容被克隆(就像表格行一样),这部分工作正常。

代码应该计算值,为每行添加一些字段。 我使用了密码功能来保持它随时更新。

为什么它不起作用?

那么我无法像这样工作。每个i_row或模板包含字段p_cnetto[] p_pvat[] p_ilosc[] (quantitiy)

因为我不能阅读行 - 我尝试了很多东西,但显然做了一些坏事,它只计算curr_net的价值,它仍然不是它应该的方式。

十进制值应该是可以接受的:例2222.00

它应该如何工作?

  1. 添加一行
  2. 总结行部分[不需要显示行聚合]:

    • curr_netto =获得此行p_cnetto[]值乘以p_ilosc[]

    • curr_brutto =得到这一行(p_cnetto[] * p_pvat[]) / 100 * p_ilosc[]

最后它应该计算所有行的总数total_netto,total_brutto - 可以在console.log中

感谢您的任何提示。

JsFiddle Example

    	<!-- statistic block --->
<div id="curr_netto"></div>
<div id="curr_brutto"></div>

<button class="btn btn-primary btn-add-panel mt-5" type="button"> <i class="glyphicon glyphicon-plus"></i> Add field</button>
<div class="row">
  <div class="col-sm-12" id="extra_group">

    <!-- s -->

    <div class="widget widget2 card template mb-2 bg-light-blue-50" style="display: none;">
      <div class="col-lg-5">
        <div class="row i_row">
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Name</label>
              <input type="text" name="p_nazwa[]" class="form-control"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Qty</label>
              <input type="text" name="p_ilosc[]" class="form-control p_ilosc"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Unit</label>
              <select class="form-control" name="p_unit[]">
                <option value="Kg">Kilogram</option>
              </select>
            </div>
          </div>


          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Net</label>
              <input type="text" name="p_cnetto[]" class="form-control p_cnetto"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>VAT</label>
              <input type="text" name="p_pvat[]" class="form-control p_pvat"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="subtot"></div>
          </div>
          <div class="form-group col-md-2">
            <button class="btn btn-danger btn-add-panel rh mt-5 ml-3"> <i class="glyphicon glyphicon-minus"></i> Del</button>
          </div>
        </div>
      </div>
    </div>




    <!-- s -->
  </div>
</div>



I am trying to create a dynamic aggregation based on fields. The only difference is that it's not a table but a div block.

What I am trying to accomplish

On button click add field, the content from the template is cloned ( it's like a table row ), this part is fully working.

The code is supposed to count the values, for each row add some fields. I used keyup function to keep it updated all time.

Why is it not working?

Well I was not able to get it working like such .each of i_row or template contains fields p_cnetto[] p_pvat[] p_ilosc[] ( quantitiy )

Because I can't read row wise - I tried many things but apparently did something bad it only counts curr_net value and it's still not the way it should be.

Decimal values should be acceptable : example 2222.00

How it should work?

  1. Add a row
  2. Summing row part [ not really need to display row aggregation ]:

    • curr_netto = get this row p_cnetto[] value multiply by p_ilosc[]

    • curr_brutto = get this row (p_cnetto[] * p_pvat[]) / 100 * p_ilosc[]

At the end it should calculate a grand total of all rows for as total_netto,total_brutto - could be in console.log

Thanks for any tips.

JsFiddle Example

    	<!-- statistic block --->
<div id="curr_netto"></div>
<div id="curr_brutto"></div>

<button class="btn btn-primary btn-add-panel mt-5" type="button"> <i class="glyphicon glyphicon-plus"></i> Add field</button>
<div class="row">
  <div class="col-sm-12" id="extra_group">

    <!-- s -->

    <div class="widget widget2 card template mb-2 bg-light-blue-50" style="display: none;">
      <div class="col-lg-5">
        <div class="row i_row">
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Name</label>
              <input type="text" name="p_nazwa[]" class="form-control"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Qty</label>
              <input type="text" name="p_ilosc[]" class="form-control p_ilosc"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Unit</label>
              <select class="form-control" name="p_unit[]">
                <option value="Kg">Kilogram</option>
              </select>
            </div>
          </div>


          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>Net</label>
              <input type="text" name="p_cnetto[]" class="form-control p_cnetto"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="form-group pmd-textfield pmd-textfield-floating-label">
              <label>VAT</label>
              <input type="text" name="p_pvat[]" class="form-control p_pvat"></input>
            </div>
          </div>
          <div class="form-group col-md-2">
            <div class="subtot"></div>
          </div>
          <div class="form-group col-md-2">
            <button class="btn btn-danger btn-add-panel rh mt-5 ml-3"> <i class="glyphicon glyphicon-minus"></i> Del</button>
          </div>
        </div>
      </div>
    </div>




    <!-- s -->
  </div>
</div>



原文:https://stackoverflow.com/questions/45633704
更新时间:2023-04-01 10:04

最满意答案

这是基于导航的应用程序的默认后退按钮样式。 您可以在创建新应用程序时通过选择基于导航的应用程序来使用它。

创建应用程序后,您必须设置视图的标题。 该视图标题将是后退按钮的标题。 如果您没有上一个视图的标题,则后退按钮不会自动出现。

你可以像这样推送视图:

    if (settingViewController == nil) {
    settingViewController = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
}

[self.navigationController pushViewController:settingViewController animated:YES];

在这种情况下,navigationController已经由Xcode创建,您必须准备settingViewController(.h,.m,.xib)。


It is default back button style of Navigation-based application. You can use it by selecting Navigation-based application when creating new application.

After created the application, you must set title of the view. That view title will be the title of back button. If you have no title of previous view, the back button will not appear automatically.

You can push view like this:

    if (settingViewController == nil) {
    settingViewController = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
}

[self.navigationController pushViewController:settingViewController animated:YES];

In this case, navigationController is already created by Xcode and you must prepare settingViewController(.h, .m, .xib).

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)