[英]How to render a List in playframework
i am wondering how i can render a List to template as an ajax callback arg. 我想知道如何将列表呈现为ajax回调arg模板。
i did this: 我这样做:
List<String> filteredTW = Twitt.filtertw(tagname);
return ok(filteredTW).as("text/plain");
but is says, i need to define ok(List) function on my own. 但是说,我需要自己定义ok(List)函数。 is it true that Playframework doesnot offer this function?
Playframework不提供此功能是真的吗?
i would be thanksful to any attemp to help.. 我将非常感谢任何尝试的帮助。
EDIT: my ajax function is: 编辑:我的ajax函数是:
$(function() {
$('.filter').click(function() {
var tagname = $(this).text();
$('.post').remove();
$.ajax({
url: '/filter',
type: 'POST',
dataType: 'html',
context: this,
data: { tags: tagname },
}).success(function(response) {
alert(response);
});
});
})
thanks 谢谢
You might want to try return ok(play.libs.Json.toJson(filteredTW));
您可能想尝试
return ok(play.libs.Json.toJson(filteredTW));
In this case, you can treat response
as a regular javascript array. 在这种情况下,您可以将
response
视为常规javascript数组。
for (i = 0; i < response.length; i++)
alert(response[i]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.