簡單的問題,但我被困...javascript設置變量條件初始化
我想設置初始化依賴於defaultQty plusmin。
所以是defaultQty = 1(如2的其它整數或3),則plusmin必須是1。
如果它不是一個整體整數(如0.5)的plusmin必須是0.1
define([
'ko',
'uiComponent'
], function (ko, Component) {
'use strict';
return Component.extend({
initialize: function() {
//initialize parent Component
this._super();
this.qty = ko.observable(this.defaultQty);
this.plusmin = 0.1;
},
decreaseQty: function() {
var newQty = this.qty() - this.plusmin;
if (newQty < this.defaultQty) {
newQty = this.defaultQty;
}
this.qty(newQty);
},
increaseQty: function() {
var newQty = this.qty() + this.plusmin;
this.qty(newQty);
}
});
});
this.plusmin =(this.qty == Math.floor(this.qty))? 1:0.1 – flowtron