ExtJS:如何获取十进制数值
我使用了 numberfield 的decimalSeparator 属性并将其设置为“,”(逗号)。现在我在将值读取为数字并用它进行数学运算时遇到问题。
我首先尝试简单:
var v = form.getForm().getValues().myfield / 2
只要输入逗号,v 就变成 NaN。
然后我尝试:
var v = Ext.util.Format.number(form.getForm().getValues().myfield, "0.000,00") / 2
一旦我输入逗号,v就会变成0。
我还尝试了在格式字符串中与/i的组合,但id也没有帮助。
我缺少什么?
I used decimalSeparator property of numberfield and set it to ',' (comma). Now I have problem reading value as number and doing math with it.
I first tried simple:
var v = form.getForm().getValues().myfield / 2
As soon s I type comma, v becomes NaN.
Then I tried:
var v = Ext.util.Format.number(form.getForm().getValues().myfield, "0.000,00") / 2
As soon a I type comma, v becomes 0.
I also tried combinations with /i in format string but id didn't help either.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是
getValues
无法按您的预期工作。来自getValues
的文档(强调我的):如果您想确保有一个十进制值,则必须执行以下操作:
编辑
您还可以尝试使用
getFieldValues
(即form.getForm().getFieldValues()
) 方法而不是getValues
方法。这应该就像您在每个表单字段上调用了getValues
一样。The problem is that
getValues
does not work as you expect. From the documentation ofgetValues
(emphasis mine):If you want to ensure that you have a decimal value, you will have to do something like the following:
EDIT
You could also try using the
getFieldValues
(i.e.form.getForm().getFieldValues()
) method instead of thegetValues
method. This should act as though you had calledgetValues
on every form field.这应该有效。
This should work.