如何在 Fluid URI ViewHelper 中使用 Javascript 变量作为参数
How to use a Javascript variable as argument in Fluid URI ViewHelper
我想从 Fluid 模板中调用 Ajax,我想使用 Fluid URI action ViewHelper。问题是,其中一个参数动态地来自 Javascript 变量。我怎样才能实现 ViewHelper 由 Fluid 渲染并且 Javascript 变量的内容在运行时插入?
这是我的代码(简化版):
function test(field) {
xmlhttp.open("GET", '<f:uri.action action="ajax" arguments="{filterfield:' + field + '}" />', true);
}
当前流体渲染输出为:
function test(field) {
xmlhttp.open("GET",'mod.php?...&tx_test_test_testview%5Bfilterfield%5D=%20%2B%20field%20%2B%20...', true);
}
但我想达到的目标是:
function test(field) {
xmlhttp.open("GET",'mod.php?...&tx_test_test_testview%5Bfilterfield%5D=' + field + '...', true);
}
我把 ...
放在输出不相关的地方。
我不认为你可以用 fluid 实现你想要的,因为 f:uri viewhelpers 最后通过 typolink 方法,它使用 urlencode 函数。也许向那里传递一些独特的字符串并使用 JS 替换它会更好?例如像这样:
function test(field) {
xmlhttp.open("GET", '<f:uri.action action="ajax" arguments="{filterfield: '___FIELD___'}" />'.replace('___FIELD___', field), true);
}
我想从 Fluid 模板中调用 Ajax,我想使用 Fluid URI action ViewHelper。问题是,其中一个参数动态地来自 Javascript 变量。我怎样才能实现 ViewHelper 由 Fluid 渲染并且 Javascript 变量的内容在运行时插入?
这是我的代码(简化版):
function test(field) {
xmlhttp.open("GET", '<f:uri.action action="ajax" arguments="{filterfield:' + field + '}" />', true);
}
当前流体渲染输出为:
function test(field) {
xmlhttp.open("GET",'mod.php?...&tx_test_test_testview%5Bfilterfield%5D=%20%2B%20field%20%2B%20...', true);
}
但我想达到的目标是:
function test(field) {
xmlhttp.open("GET",'mod.php?...&tx_test_test_testview%5Bfilterfield%5D=' + field + '...', true);
}
我把 ...
放在输出不相关的地方。
我不认为你可以用 fluid 实现你想要的,因为 f:uri viewhelpers 最后通过 typolink 方法,它使用 urlencode 函数。也许向那里传递一些独特的字符串并使用 JS 替换它会更好?例如像这样:
function test(field) {
xmlhttp.open("GET", '<f:uri.action action="ajax" arguments="{filterfield: '___FIELD___'}" />'.replace('___FIELD___', field), true);
}