<form class="product-form">
<div class="col-lg-2 product">
<h3>{{$p->name}}</h3>
<img src="{{$p->image}}" width="200" height="200"><br>
<h3>{{$p->price}}</h3>
<button type="submit" onclick="addProductInCart(this)" >Добавить в корзину</button>
<input type="hidden" name = "idVal" value = "{{$p->id}}">
{{ csrf_field() }}
</div>
</form>
Дайте форму классу. Теперь вы можете получить значения, связанные с ним.
$('.product-form').submit(function() {
alert($(this).serialize());
var product = 1;
var token = $("input[name=_token]").val();
$.ajax({
type: "POST",
url: "addToCart",
data: {"_token": token, "product": product},
success: function (result) {
$("#product-count").html(result);
}
})
return false;
});
Вы можете попробовать транспонировать кадр данных, затем после подсчета только ненулевые значения и последний набор 1
#bit of complex procedure, solution involving with.
def fill_values(df):
df = df[::-1]
a = df == 1
b = a.cumsum()
#Function in counting the cummulative not null values
arr = np.where(a, b-b.mask(a).ffill().fillna(0).astype(int), 1)
return (b-b.mask(a).ffill().fillna(0).astype(int))[::-1]*20
df.apply(fill_values,1).replace(0,np.nan)-20
Out:
20 40 60 80 100 120 140
1 40.0 20.0 0.0 NaN NaN NaN NaN
2 80.0 60.0 40.0 20.0 0.0 NaN NaN
3 60.0 40.0 20.0 0.0 NaN NaN NaN
4 20.0 0.0 NaN NaN 40.0 20.0 0.0