我正在使用 omnifaces <o:commandScript>-tag
ajax 加载滚动数据。目前这个片段工作正常,但我想知道,是否可以从外部 js 文件引用函数名以避免在 xhtml 文件中定义所有这些脚本:
产品.xhtml:
<o:commandScript name="loadNext" actionListener="#{productBean.loadNext}" render="products"/>
<script type="text/javascript">
$('.scrollSpy').on('inview.uk.scrollspy', function() { //UIKit scrollspy listener
loadNext();
});
</script>
<h:panelGroup id="products">
<div class="box scrollSpy">
...
</div>
</h:panelGroup>
我正在寻找类似的东西:
产品.xhtml:
<o:commandScript name="GENERIC.loadNext"
actionListener="#{productBean.loadNext}"/>
通用.js:
var GENERIC = (function () {
var my = {};
my.loadNext = function (){} //empty
my.productsLoaded = function (){
//doSomething
}
$(document).ready(function(){
$('.scrollSpy').on('inview.uk.scrollspy', function() {
my.loadNext();
});
});
return my;
})()
但是我明白了
[o:commandScript 'name' attribute 'GENERIC.loadNext' does not represent a valid script function name.]
虽然来自 generic.js 的一般调用工作正常,例如
<f:ajax listener="#{productBean.refresh}" render="products" onevent="GENERIC.productsLoaded"/>
提前感谢您的建议。
最佳答案
这个要求从一开始就没有被考虑到。根据 issue 218我已经为当前的 2.3 SNAPSHOT 修复了它。
<o:commandScript>
won't anymore认为(正确放置的)句点无效并省略显式 var
名称中出现句点时的声明。
关于javascript - <o :commandScript>: reference namespaced JS function name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35937545/