首页 > 解决方案 > 在 TYPO3 后端添加 jQuery 函数

问题描述

当我打开“页面”视图时,我需要在我的 TYPO3 后端自定义 jQuery 函数。

我为 preProcess 添加了一个钩子

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'] 
['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'] 
['tx_dashboard'] =
    \vendor\dashboard\Hooks\Backend\IconCorrection::class;

在我的 IconCorrection 中我添加了

public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
{
    GeneralUtility::makeInstance(PageRenderer::class)
        ->addRequireJsConfiguration([
            'paths' => [
                'iconCorrection'=>'/typo3conf/ext/dashboard/Resources/Public/JavaScript/hidePreviewIcon.js',
            ],
            'shim' => [
                'iconCorrection' => ['jquery'],
            ],
        ]);

}
}

在我的 hidePreviewIcon.js 我有一个 console.log 我想要类似的东西,$(".btn").hide();但现在只是测试 js 是否已加载。

在我的开发工具中,我看到 js 已加载,但未执行 console.log。

我缺少什么?我可以 使用 TYPO3 v8.7.2addJsFile而不是ImaddRequireJsConfiguration

编辑:

我添加了

$renderer =\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$renderer->addJsFile('/typo3conf/ext/trumpf_editordashboard/Resources/Public/JavaScript/hidePreviewIcon.js', 'text/javascript', false, false, '', true, '|', false, '');

到我的preProcess()功能。

现在 .js 已加载并执行 console.log(); 但我的

$(document).ready(){$(".btn").hide(); 

不工作。我认为它执行得太早了

编辑2:诀窍:

$(function(){
$('#typo3-contentIframe').ready(function(){
    console.log("loaded");
    $(".btn").hide();

});
});

标签: phptypo3extbase

解决方案


推荐阅读