根据动态添加的字段计算值(Calculating values based on dynamically added fields)
我正在尝试基于字段创建动态聚合。 唯一的区别是它不是一个表格而是一个div区块。
我正在努力完成的
在按钮上单击添加字段,模板中的内容被克隆(就像表格行一样),这部分工作正常。
代码应该计算值,为每行添加一些字段。 我使用了密码功能来保持它随时更新。
为什么它不起作用?
那么我无法像这样工作。每个i_row或模板包含字段
p_cnetto[] p_pvat[] p_ilosc[]
(quantitiy)因为我不能阅读行 - 我尝试了很多东西,但显然做了一些坏事,它只计算curr_net的价值,它仍然不是它应该的方式。
十进制值应该是可以接受的:例2222.00
它应该如何工作?
- 添加一行
总结行部分[不需要显示行聚合]:
curr_netto =获得此行
p_cnetto[]
值乘以p_ilosc[]
curr_brutto =得到这一行
(p_cnetto[] * p_pvat[]) / 100 * p_ilosc[]
最后它应该计算所有行的总数total_netto,total_brutto - 可以在console.log中
感谢您的任何提示。
<!-- 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?
- Add a row
Summing row part [ not really need to display row aggregation ]:
curr_netto = get this row
p_cnetto[]
value multiply byp_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.
<!-- 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
最满意答案
这是基于导航的应用程序的默认后退按钮样式。 您可以在创建新应用程序时通过选择基于导航的应用程序来使用它。
创建应用程序后,您必须设置视图的标题。 该视图标题将是后退按钮的标题。 如果您没有上一个视图的标题,则后退按钮不会自动出现。
你可以像这样推送视图:
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).
相关问答
更多-
这是基于导航的应用程序的默认后退按钮样式。 您可以在创建新应用程序时通过选择基于导航的应用程序来使用它。 创建应用程序后,您必须设置视图的标题。 该视图标题将是后退按钮的标题。 如果您没有上一个视图的标题,则后退按钮不会自动出现。 你可以像这样推送视图: if (settingViewController == nil) { settingViewController = [[SettingViewController alloc] initWithNibName:@"SettingView ...
-
我相信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 as ex ...
-
后退按钮的标题始终是第二个顶视图控制器的标题。 因此你可以使用(在确保有≥2个视图控制器之后): NSArray* viewCtrlers = self.navigationController.viewControllers; UIViewController* prevCtrler = [viewCtrlers objectAtIndex:[viewCtrlers count]-2]; return prevCtrler.title; 如果你想要一个绿色按钮,为什么不简单地将导航栏的色调设置为绿色? ...
-
viewDidLoad方法在视图控制器完成加载并设置视图控制器时调用,例如加载NIB文件。 为了您的需要,您应该将相关代码移到viewWillAppear ,每当相应的视图控制器变为可见时就会调用它。 因此,对于转换A -> B -> C (backto)-> B , B的视图控制器的viewWillAppear方法将被调用两次。 The viewDidLoad method is called when the view controller has finished loading and settin ...
-
如何在手机应用程序中处理iPhone上丢失的hw后退按钮?(How to deal with missing hw back button on iphone in a phonegap app?)[2023-02-12]
实际上我前几天刚回答了这样的问题。 你可以在这里找到它。 简而言之,见下文: 确保在每个要使用inappbrowser的页面中都有 您不需要在config.xml中包含插件标记。 我很确定在2.5左右它们在核心构建功能中包含了inappbrowser。 要在inappbrowser中打开链接,请使用以下javascript: function openURL(urlString){ myURL = encodeURI(urlStr ... -
只要UIWebView可以通过执行如下操作来返回选项,您可以用浏览器后退按钮替换导航栏的后退按钮: - (void)updateBackButton { if ([self.webView canGoBack]) { if (!self.navigationItem.leftBarButtonItem) { [self.navigationItem setHidesBackButton:YES animated:YES]; UIBarB ...
-
这听起来像你想要做的是使用UINavigationController。 如果使用initWithRootViewController初始化程序实例化UINavigationController,则可以将它传递给第一个UIViewController。 然后,您只需要将所需的任何操作绑定到调用[myUINavigationController pushViewController:myOtherViewController animated:YES]以使其滑动到第二个视图。 UINavigationCont ...
-
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];
-
尝试一下。 它是下面简单的代码 FirsViewController.m - (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]; ...
-
不要使用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 loads.