我想计算总数=数量*价格,并在更改数量或价格时更新总数。 image
我的HTML代码是:
library(data.table)
library(plyr)
new <- function(df) {
upper=0
ds <- split(df, f = df$main) #this col have rows on which I split the df
s <- sapply(ds, function(x) sort(x$mean)) # this is the col with mean values needed for t.test()
n <- mapply(FUN = function(x) {sort(x)}, x = s)
l <- mapply(FUN = function(x) {length(x)}, x = s)
for (j in l) {
for(i in 1:(j-1)) {
for (k in n) {
upper <- c(upper, k[i])
lower <- k[-c(upper:i)]
t <- t.test(upper, lower, var.equal = TRUE, na.rm=TRUE)
print(t[['p.value']])
}
}
}
}
Error in t.test.default(upper, lower, var.equal = TRUE, na.rm = TRUE) :
not enough 'y' observations
In addition: There were 50 or more warnings (use warnings() to see the
first 50)
> warnings()
Warning messages:
1: In -upper:-i : numerical expression has 2 elements: only the first used
我的代码:
<form [formGroup]="editform" (ngSubmit)="edisale()" class="col s12" materialize>
<div class="form-group">
<table align="center" class="table table-bordered table-hover">
<thead>
<tr style="color:black;">
<th>Price</th>
<th>Quantity</th>
<th>Notes</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<tr formArrayName="products" class="group" style="cursor: pointer" *ngFor="let sale of editform.get('products').value; let i = index" [formGroupName]="i">
<td>
<input class="form-control" id="p_unit_price " type="number" class="validate" [value]="sale.p_unit_price" ng-change="tot()">
</td>
<td>
<input class="form-control" type="text" formControlName="p_quantity" id="p_quantity" name="p_quantity" [value]="sale.p_quantity" ng-change="tot()" >
</td>
<td>
<div class="input-field col s2">
<input class="form-control" formControlName="p_description" id="p_description" type="text" class="validate" [value]="sale.p_description">
</div>
</td>
<td>
<input class="form-control" type="text" formControlName="p_subtotal" id="p_subtotal" name="p_subtotal" [value]="(sale.p_subtotal)">
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
<div class="row">
<div class="input-field col s2" style="float: right;">
Total: {{Total}} ALL
<input class="form-control" formControlName="total" id="total" type="text" class="validate" [value]="totale">
</div>
<div class="form-control" class="input-field col s2" style="float: right;">
Amount Paid:
<input class="form-control" formControlName="amount_paid" id="amount_paid" type="text" class="validate">
</div>
<div class="input-field col s2" style="float: right;">
Subtotal:
<input formControlName="subtotal" id="subtotal" type="text" class="validate" [value]="Total">
</div>
</div>
</form>
当我更改数量或价格时,总共没有任何变化。你能告诉我任何想法或我的代码中有什么问题吗?谢谢
答案 0 :(得分:0)
添加(更改)=&#34; somefunction()&#34;并使用[(ngModel)] =&#34; var1&#34;创建双向绑定在你的输入
export class ComponentName {
var1;var2; var3;
constructor(
) { }
functionName(){
// when you change your input this method is called and then manipulate your variable.
}
}