TYPO3 extbase-jQuery的可变变量 [英] TYPO3 extbase - fluid variable to jquery

查看:92
本文介绍了TYPO3 extbase-jQuery的可变变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将流体变量从控制器传递给jQuery或JavaScript?

How could one pass a fluid variable from the controller to jQuery or JavaScript?

在我的控制器内部:

public function tabs () {
    $this->view->assign('tab', 1);
}

在流体内部,我将变量用作{tab} 但是如何传递给JavaScript?任何帮助将不胜感激...

Inside fluid I'd use the variable as {tab} But how can I pass to JavaScript? Any help would be appreciated...

推荐答案

在大多数情况下,JS在流体模板中的行为是……很糟糕,如果您的JS代码包含任何花括号,则需要包括外部脚本,而不是将脚本放在视图.

JS in fluid templates behaviour is ... terrible in most cases, if your JS code contains any curly brackets you need to include external script instead placing the script in the view.

原因是Fluid认为所有大括号都属于它的作用域,因此在编写时:

The reason is that Fluid thinks, that all curly brackets belongs to its scope, so when you write:

$('#mySelectBox').change(function() {
    // functions body code
    // next line
    // next line
});

Fluid破坏了JS并将其呈现为:

Fluid destroys the JS and renders it as just:

$('#mySelectBox').change(function() Array);

然后我经常使用这样的东西:

Then most often I use something like this:

:

<script>var TxMyExtKeyTabNumber = {tab}</script>
<script src="path/to/static/script.js"></script>

在script.js中:

$("#container").val(TxMyExtKeyTabNumber);

这篇关于TYPO3 extbase-jQuery的可变变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆