我正在 prestashop 1.5 中开发一个模块。我使用 displayAdminProductsExtra Hook 在管理选项卡中显示 tpl 文件。当我将 jquery 代码包含在 tpl 中时,它工作正常。但是当我尝试将其作为新文件并包含它时,它不起作用。到目前为止我尝试了以下方法..
使用displayBackOfficeHeader注册一个钩子(Hook)并像这样调用..
public function hookdisplayBackOfficeHeader($params)
{
$this->context->controller->addJS(($this->_path).'abc.js');
}
我尝试将它添加到 displayAdminProductsExtra 中,也像这样..
$this->context->controller->addJS(_MODULE_DIR_.$this->module->name.'/views/js/abc.js'); //first tried..
$this->context->controller->addJS(($this->_path).'abc.js','all'); //second tried this..
我尝试过这样的 getcontent ..
public function getContent()
{
$this->_html= '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
<script src="../modules/abc/abc.js" type="text/javascript" ></script>';
return $this->_html;
}
但是这些方法没有添加我的js文件。不知道我在哪里犯了错误。任何帮助将不胜感激。
最佳答案
当您创建 Prestashop 模块时,您必须添加函数 hookHeader 以及在其中添加页面中 js 的行。
需要这样的东西:
public function hookHeader ($ params)
{
$ this-> controller-> addJS (($ this-> _path). 'abc.js');
}
另一方面,查看 blockcategories.php 文件中模块 blockcategories 的代码,我们会看到以下内容:
public function displayForm()
{
...
}
该功能是创建一个模块配置页面,与使用其他模块的方法相同。也许这是一个更简单的选择,但开发速度更快。
问候
关于jquery - 如何在prestashop 1.5中为模块添加JS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18415870/