2

Js file

qtyOptions: ko.observableArray([]),  
initialize: function () {
this._super();                 
for (var i = 1; i <= 4; i++) {
    this.qtyOptions.push(i);
}
return this;

template file

<!-- ko if: stockQty > 10 -->
<select data-bind="attr: {
     id: 'cart-item-'+item_id+'-qty',
     'data-cart-item': item_id,
     'data-item-qty': qty,
     'data-cart-item-id': product_sku
     }, value: qty, options: $parent.qtyOptions"></select>
<!-- /ko -->

How to get template stockQty value into js file like this

for (var i = 1; i <= stockQty; i++) {
    this.qtyOptions.push(i);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.