根据动态添加的字段计算值(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).

相关问答

更多

如何在iPhone中获得这种后退按钮(How to get this kind of back button in iphone)

这是基于导航的应用程序的默认后退按钮样式。 您可以在创建新应用程序时通过选择基于导航的应用程序来使用它。 创建应用程序后,您必须设置视图的标题。 该视图标题将是后退按钮的标题。 如果您没有上一个视图的标题,则后退按钮不会自动出现。 你可以像这样推送视图: if (settingViewController == nil) { settingViewController = [[SettingViewController alloc] initWithNibName:@"Settin...

iPhone 6+没有导航栏后退按钮项(iPhone 6+ does not have navigation bar back button item)

我相信iPhone 6+模拟器中存在一个错误 - 我也观察到了类似的行为,但仅限于模拟器上。 在真正的iPhone 6+上运行应用程序按预期工作 - 导航栏和所有按钮一样。 I believe there is a bug in the iPhone 6+ simulator - I have also observed a similar behavior, but only on the simulator. Running the app on a real iPhone 6+ works ...

iPhone如何获得自定义后退按钮的标题(iPhone how to get the title for a custom Back-Button)

后退按钮的标题始终是第二个顶视图控制器的标题。 因此你可以使用(在确保有≥2个视图控制器之后): NSArray* viewCtrlers = self.navigationController.viewControllers; UIViewController* prevCtrler = [viewCtrlers objectAtIndex:[viewCtrlers count]-2]; return prevCtrler.title; 如果你想要一个绿色按钮,为什么不简单地将导航栏的色调设置...

如何在UINavigationController中按下后退按钮时调用viewDidLoad方法?(How to call viewDidLoad method when back button is pressed in UINavigationController? (iPhone / iPad))

viewDidLoad方法在视图控制器完成加载并设置视图控制器时调用,例如加载NIB文件。 为了您的需要,您应该将相关代码移到viewWillAppear ,每当相应的视图控制器变为可见时就会调用它。 因此,对于转换A -> B -> C (backto)-> B , B的视图控制器的viewWillAppear方法将被调用两次。 The viewDidLoad method is called when the view controller has finished loading and s...

如何在手机应用程序中处理iPhone上丢失的hw后退按钮?(How to deal with missing hw back button on iphone in a phonegap app?)

实际上我前几天刚回答了这样的问题。 你可以在这里找到它。 简而言之,见下文: 确保在每个要使用inappbrowser的页面中都有<script src="phonegap.js"></script> 您不需要在config.xml中包含插件标记。 我很确定在2.5左右它们在核心构建功能中包含了inappbrowser。 要在inappbrowser中打开链接,请使用以下javascript: function openURL(urlString){ myURL = encodeURI(u...

如何将navigationcontroller的后退按钮转换为iPhone中的浏览器后退按钮?(How to convert navigationcontroller's back button into browser's back button in iPhone?)

只要UIWebView可以通过执行如下操作来返回选项,您可以用浏览器后退按钮替换导航栏的后退按钮: - (void)updateBackButton { if ([self.webView canGoBack]) { if (!self.navigationItem.leftBarButtonItem) { [self.navigationItem setHidesBackButton:YES animated:YES]; U...

如何隐藏iPhone上第一个视图中的后退按钮?(How to hide back button in the first view on iPhone?)

这听起来像你想要做的是使用UINavigationController。 如果使用initWithRootViewController初始化程序实例化UINavigationController,则可以将它传递给第一个UIViewController。 然后,您只需要将所需的任何操作绑定到调用[myUINavigationController pushViewController:myOtherViewController animated:YES]以使其滑动到第二个视图。 UINavigatio...

如何禁用iPhone应用程序中的后退按钮(How to disable back button in iPhone Application)

self.navigationItem.hidesBackButton = YES; 当你完成加载时, [self.navigationItem setHidesBackButton:NO animated:YES]; self.navigationItem.hidesBackButton = YES; When you're done loading, [self.navigationItem setHidesBackButton:NO animated:YES];

iPhone SDK:自定义后退按钮标题(iPhone SDK: Customizing back button title)

尝试一下。 它是下面简单的代码 FirsViewController.m - (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]; ...

导航控制器(iPhone)的后退按钮问题(Back Button Issues With Navigation Controller (iPhone))

不要使用viewDidLoad ,使用viewWillAppear:或viewDidAppear:取决于哪个看起来更适合你)。 viewDidLoad仅在视图加载时调用一次。 Don't use viewDidLoad, use viewWillAppear: or viewDidAppear: (depending on which looks better for you). viewDidLoad is only called once, the first time the view lo...

相关文章

更多

Storm 中 Fields作用

之前一直没搞清楚Fields的作用,今天再看一个例子的时候突然脑洞大开,想通了!看得例子如下。 Tra ...

Java-based 实现的索引复制

solr 包含一个基于 Java-based 实现的索引复制,通过http方式完成。 这 ...

Storm【设计细节】 -Fields对象

本章主题: 记录一个小小的Tips 1 Storm在Emit publicclassValuesext ...

el表达式如何动态获得某一个字段的值?

比如 class User{ Integer userId; String userName; ...

Solr官方文档系列——Text Analysis

Text fields are typically indexed by breaking the t ...

elasticsearch 添加字段

Elasticsearch中的mapping一旦创建,就不能再修改。但是添加字段是可以的。其实很简单, ...

ibatis中如何配置,动态字段

如何动态配置显示字段 如:select name password from table1 ...

[How to] Make custom search with Nutch(v 1.0)?(转)

http://puretech.paawak.com/2009/04/29/how-to-make-c ...

Guava Booleans类-布尔型基本的实用工具类

static int countTrue(boolean... values)返回为true值的数目

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本