If you want a more general solution, you can do something like this
(function () {
ko.extenders.isCurrency = function (target, options) {
var result = ko.dependentObservable({
read: function () {
return Globalize.format(target(), "c");
},
write: target
});
result.raw = target;
return result;
};
} ());
ViewModel = function() {
this.cashIsKing = ko.observable(565345.56435535).extend({ isCurrency: true});
};
ko.applyBindings(new ViewModel());
http://jsfiddle.net/5H5AK/
edit: instead of using true as parameters, you can provide an object literal with parameters and use it from the isCurrency expander
source
share