ractive.subtract()
edit this pageDecrements the value of the given keypath.
ractive.subtract( keypath[, number ])
Returns a
Promise
(see Promises)keypath
String
The keypath of the number we're decrementing, e.g.
count
number
Defaults to
1
. The number to decrement by
Example
This is useful for numeric counters. Instead of using ractive.get() and ractive.set() in succession, using add() and subtract() will simplify your code.
quantityBox = new Ractive({
template: [
"<button on-click='decrease'> - </button>",
"<span></span>",
"<button on-click='increase'> + </button>",
].join(""),
data: {
quantity: 20
}
});
quantityBox.on({
decrease: function () { this.subtract(); },
increase: function () { this.add(); }
}
});