淘汰赛js和全球化 [英] knockout js and globalization
问题描述
我无法弄清楚如何处理利用基因敲除JS和非美国地区的计算。我的逗号,并使用jquery.globalization插件验证正确,但淘汰赛计算给了我一个非数字。是否淘汰赛JS支持这种以任何方式或是否存在任何变通办法?
I can't figure out how to handle calculations using knockout js and a non us locale. My comma is , and is validated correctly using the jquery.globalization plugin but the knockout calculation is giving me a NaN. Does knockout js support this in any way or does it exist any workarounds?
示例:
请在淘汰赛JS现场工作允许十进制值的数量字段,允许输入的全球化(如逗号符号)和输出格式的cartEditor例如
Make the cartEditor example on the knockout js site work allowing decimal values in the quantity field and allowing globalized input (, as comma sign) and output formatting
<一个href=\"http://knockoutjs.com/examples/cartEditor.html\">http://knockoutjs.com/examples/cartEditor.html
我需要这一个asp.net MVC 3网站的工作,因为我使用的是NB-NO文化和模型绑定期待运行网站,逗号标志
I need this to work on a asp.net mvc 3 site because I am running the site using the nb-NO culture and the model binder is expecting , as the comma sign
推荐答案
我做了这样的事情,写入一个包裹 autoNumeric自定义绑定。 JS 的格式。 (要点)
I did something like this by writing a custom binding that wrapped autoNumeric.js for the formatting. (gist)
ko.bindingHandlers.autoNumeric = function ($) {
function getElementValue(el) {
return parseFloat(el.autoNumericGet(), 10);
}
function getModelValue(accessor) {
return parseFloat(ko.utils.unwrapObservable(accessor()), 10);
}
return {
init: function (el, valueAccessor, bindingsAccessor, viewModel) {
var $el = $(el),
bindings = bindingsAccessor(),
settings = bindings.settings,
value = valueAccessor();
function updateModelValue() {
value(getElementValue($el));
};
$el.autoNumeric(settings);
$el.autoNumericSet(getModelValue(value), settings);
$el.change(updateModelValue);
},
update: function (el, valueAccessor, bindingsAccessor, viewModel) {
var $el = $(el),
newValue = getModelValue(valueAccessor()),
elementValue = getElementValue($el),
valueHasChanged = (newValue != elementValue);
if ((newValue === 0) && (elementValue !== 0) && (elementValue !== "0")) {
valueHasChanged = true;
}
if (valueHasChanged) {
$el.autoNumericSet(newValue);
setTimeout(function () { $el.change() }, 0);
}
}
};
}
数据使用这个自定义autoNumeric结合看起来像这样绑定:
the data binding using this custom autoNumeric binding looks like this:
<input data-bind="autoNumeric:amount, settings:{aSign:'$'}" />
查看autoNumeric.js多种选项,可以格式化,看看你能做些什么ewith的设置。
Check out autoNumeric.js extensive options for formatting to see what you can do ewith the settings.
这篇关于淘汰赛js和全球化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!