我有一个带有 symfony2 的 json api:
return new JsonResponse(array(
'deliveryRange' => $deliveryRange,
'html' => $this->render(':App:Command/deliveryRange.html.twig'),
));
传递范围是一个数组,html变量将我的twig模板发送回。
这是我的 JS:
callDeliveryRange: function(){
$.ajax({
type: "POST",
url: Command.routeApiRange,
cache: false,
data: {},
success: function (data, status) {
Command.htmlDeliveryRange(data);
},
})
},
htmlDeliveryRange: function(data){
$('#content-delivery-range').html(data.html);
},
在 htmlDeliveryRange 函数中,我想将 twig 模板附加到我的新 twig 文件中。
但是什么也没发生。
我还想在模板中使用 data.deliveryRange 变量。
可能吗?
最佳答案
尝试一下:
return new JsonResponse([
'deliveryRange' => $deliveryRange,
'html' => $this->renderView(':App:Command/deliveryRange.html.twig'),
]);
关于javascript - 在JS中调用twig模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37030849/