[英]WidgetVar InputNumber Primefaces 6.1 not working
我從Primefaces 5.2遷移到6.1。 但是,我在inputNumber中使用widgetVar來解決javascript的操作。 但是,widgetVar在6.1版本中不適用於inputNumber。
例:
頭
<h:head>
<title>TODO supply a title</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<h:outputScript name="jquery/jquery.js" library="primefaces" />
<h:outputScript name="jquery/jquery-plugins.js" library="primefaces" />
<h:outputScript name="core.js" library="primefaces" />
<h:outputScript name="components.js" library="primefaces" />
</h:head>
<p:inputNumber thousandSeparator="." decimalSeparator="," widgetVar="wInput"
onchange="valueForInput('wInput')"/>
<script>
function valueForInput(wInput){
var inputNumber = PF(wInput);
console.log(inputNumber.getValue());
}
</script>
控制台錯誤
Uncaught TypeError: Cannot read property 'getValue' of undefined
at valueForInput (http://localhost:8084/sgwapp/:15:40)
at HTMLInputElement.onchange (http://localhost:8084/sgwapp/:11:2197)
at Object.trigger (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:4585:27)
at HTMLInputElement.<anonymous> (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:5289:17)
at Function.each (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:384:23)
at jQuery.fn.init.each (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:136:17)
at jQuery.fn.init.trigger (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:5288:15)
at jQuery.fn.init.jQuery.fn.(anonymous function) [as change] (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:8481:9)
at c.setValueToHiddenInput (http://localhost:8084/sgwapp/javax.faces.resource/inputnumber/inputnumber.js.xhtml?ln=primefaces&v=6.1:3:1714)
at copyValueToHiddenInput (http://localhost:8084/sgwapp/javax.faces.resource/inputnumber/inputnumber.js.xhtml?ln=primefaces&v=6.1:3:1542)
valueForInput @ (index):15
onchange @ (index):11
trigger @ jquery.js.xhtml?ln=primefaces&v=6.1:4585
(anonymous) @ jquery.js.xhtml?ln=primefaces&v=6.1:5289
each @ jquery.js.xhtml?ln=primefaces&v=6.1:384
each @ jquery.js.xhtml?ln=primefaces&v=6.1:136
trigger @ jquery.js.xhtml?ln=primefaces&v=6.1:5288
jQuery.fn.(anonymous function) @ jquery.js.xhtml?ln=primefaces&v=6.1:8481
setValueToHiddenInput @ inputnumber.js.xhtml?ln=primefaces&v=6.1:3
copyValueToHiddenInput @ inputnumber.js.xhtml?ln=primefaces&v=6.1:3
init @ inputnumber.js.xhtml?ln=primefaces&v=6.1:3
e.(anonymous function) @ core.js.xhtml?ln=primefaces&v=6.1:5
c @ core.js.xhtml?ln=primefaces&v=6.1:5
createWidget @ core.js.xhtml?ln=primefaces&v=6.1:1
cw @ core.js.xhtml?ln=primefaces&v=6.1:1
(anonymous) @ (index):11
fire @ jquery.js.xhtml?ln=primefaces&v=6.1:3148
fireWith @ jquery.js.xhtml?ln=primefaces&v=6.1:3260
ready @ jquery.js.xhtml?ln=primefaces&v=6.1:3472
completed @ jquery.js.xhtml?ln=primefaces&v=6.1:3503
您可以在堆棧中看到在構建小部件期間觸發了onchange偵聽器,這就是為什么無法通過PF
函數找到它的原因-它尚未准備好。
無論如何,您可能對初始值不感興趣,因此請跳過此調用:
function valueForInput(wInput){
if (PF(wInput)) {
var inputNumber = PF(wInput);
console.log(inputNumber.getValue());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.