[英]symfony2 js twig
i wanna pass a json result parameter to a twig format in file "A.js.twig" as follow: 我想将json结果参数传递给文件“ A.js.twig”中的小枝格式,如下所示:
$.ajax({
type: 'POST',
url: "managemore",
success: function(msg){
var ret = $.parseJSON(msg)
var str = '';
for (var i=0; i<ret.deliverLength; i++)
{
str = str + "<a href=\" {{ path('changeJob', {'jid':ret.deliver[i]['jid']}) }} \", target=\"_self\" ><li>hello</li></a>";
}
},
error: function(XmlHttpRequest,textStatus, errorThrown){
alert("fail");
}
});
it went wrong...so how can i pass the ret.deliver[i]["jid"] in the twig format in the right way? 它出了错...所以我该如何以正确的方式以细枝格式传递ret.deliver [i] [“ jid”]? Thanks a lot.
非常感谢。
Check documentation for FOSJsRoutingBundle : https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/index.md 查看FOSJsRoutingBundle的文档: https : //github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/index.md
To generate route using this bundle use one of example statements: 要使用此捆绑包生成路由,请使用以下示例语句之一:
Routing.generate('my_route_to_expose', { id: 10 });
// will result in /foo/10/bar
Routing.generate('my_route_to_expose', { id: 10, foo: "bar" });
// will result in /foo/10/bar?foo=bar
$.get(Routing.generate('my_route_to_expose', { id: 10, foo: "bar" }));
// will call /foo/10/bar?foo=bar
Routing.generate('my_route_to_expose_with_defaults');
// will result in /blog/1
Routing.generate('my_route_to_expose_with_defaults', { id: 2 });
// will result in /blog/2
Routing.generate('my_route_to_expose_with_defaults', { foo: "bar" });
// will result in /blog/1?foo=bar
Routing.generate('my_route_to_expose_with_defaults', { id: 2, foo: "bar" });
// will result in /blog/2?foo=bar
For your problem it will looks smt like this: 对于您的问题,它将看起来像这样:
str = str + Routing.generate('changeJob', { jid: ret.deliver[i]['jid']}) + <li>hello</li> </a>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.