1

我希望通过apex:component调用我的脚本。因此,我不想在我的页面上包含 3 个包含,而是

<c: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>

有没有一种优雅的方式来做到这一点?

干杯

4

1 回答 1

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>
于 2013-11-06T17:09:12.377 回答