我希望通过apex:component调用我的脚本。因此,我想要
而不是在我的页面上有3个包含<c:scripts />
和'scripts'组件将包含以下内容。
<apex:component >
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-1.9.1.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-ui-1.10.3.custom.min.js') }" />
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/anotherScript.js') }" />
</apex:component>
但是如果我只想要其中一个脚本,我可以将一个参数传递给组件调用吗?像下面这样......
<c:scripts
myScript = true />
然后是组件......
<apex:component >
Boolean myScript = <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-1.9.1.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-ui-1.10.3.custom.min.js') }" />
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/anotherScript.js') }" />
</apex:component>
这样做有一种优雅的方法吗?
干杯
答案 0 :(得分:1)
找到答案:)
<apex:component>
<apex:attribute name="includejQuery" type="Boolean" required="false" default="false" description="True to include jQuery" />
<apex:outputPanel layout="none" rendered="{!includejQuery}">
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-1.9.1.js')}"/>
</apex:outputPanel>
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-ui-1.10.3.custom.min.js') }" />
<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/anotherScript.js') }" />
</apex:component>
然后在我的页面中:
<apex:page>
...
<c:Scripts includejQuery="true" />
...
</apex:page>