javascript 如何在javascript中获取托管bean属性值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14812163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get managed bean property value inside javascript
提问by Bob Samadi
Can anyone tell me how to get the managed bean property value inside the javascript method
谁能告诉我如何在 javascript 方法中获取托管 bean 属性值
something like
就像是
function fonction1() {
var variable = "#{myBean.property}";
}
回答by Daniel
You can like this:
你可以喜欢这个:
<h:inputText id="propertyId" value="#{myBean.property}" style="display:none"/>
and access it like this (note that if its inside a form you might need to add the form prefix)
并像这样访问它(请注意,如果它在表单中,您可能需要添加表单前缀)
alert($('#propertyId').val()); // or alert($('#myFormId\:propertyId').val());
回答by fmsf
I guess you want it to be updated to the current value inside the bean. You can't! You can only add it to javascript during load time. If you want it to be updated you will have to do ajax calls to fetch the current value.
我猜您希望它更新为 bean 内的当前值。你不能!您只能在加载期间将其添加到 javascript。如果您希望它被更新,您将不得不执行 ajax 调用来获取当前值。