I am trying to use ZendX_jQuery and Datatables for a project. In my layout file I have:
if($this->jQuery()->isEnabled()){
$this->jQuery()->开发者_开发技巧;setLocalPath('/js/jquery/js/jquery-1.4.2.min.js')
->setUiLocalPath('/js/jquery/js/jquery-ui-1.8.4.custom.min.js')
->addStylesheet('/css/smoothness/custom.css')
->addJavascriptFile('/js/jquery.dataTables.js');
echo $this->jQuery();
}
Whenever I have object being rendered that use the ZendX helper, the datatables object renders fine. However, if I dont have an object then the table wont render.
Examples:
Datatables working because of datepicker:
<link rel="stylesheet" href="/css/smoothness/custom.css" type="text/css" media="screen" />
<script type="text/javascript" src="/js/jquery/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/jquery/js/jquery-ui-1.8.4.custom.min.js"></script>
<script type="text/javascript" src="/js/jquery.dataTables.js"></script>
Datatables broken because no datepicker:
<link rel="stylesheet" href="/css/smoothness/custom.css" type="text/css" media="screen" />
<script type="text/javascript" src="/js/jquery/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/jquery.dataTables.js"></script>
The obvious difference here is that without other jQuery objects, ZendX won't place the jQuery UI file in the header. Is there a way to force it to do so? I dont like having to declare the UI script file twice to make sure every page gets it.
Thanks,
Joe Chin
You have to enable it yourself, which is otherwise done internally.
To access the javascript we have to utilize the jQuery() functionality. Both helpers already activated their dependencies that is they have called jQuery()->enable() and jQuery()->uiEnable() [...]
Source
That's referring to the view helper for jQuery, so it's $this->view->jQuery()->enable()
within a controllers action or $this->jQuery()->enable()
within a view.
精彩评论