1
저는 Play Framework를 사용하고 있으며 AJAX를 사용하여 호출 할 스크립트에 부분보기를 반환하고자합니다. 저는 ASP.NET MVC의 세계에서 왔습니다. 아주 간단한 컨셉입니다.하지만 Play에서 그 곳을 볼 수는 없습니다.Play Framework 반환 부분보기
내가하고 싶은 것이의 예 :
Main.html
<html>
<head><title>Test</title></head>
<body>
<h1>Here's my list</h1>
<input type="text" id="new-entry" /><button id="add-new-entry">Add</button>
<ul id="item-list">
#{list items, as:'item'}
<li>#{anitemtemplate item}</li>
#{/list}
</ul>
<script>
$(function() {
$("#add-new-entry").click(function() {
var action = #{jsAction @add(':name') /};
var title = $("#new-entry").val();
$.post(action(title), null, function(data) {
var newData = $(document.createElement("li")).html(data);
$("#item-list").append(newData);
});
});
});
</script>
</body>
</html>
anitemtemplate.html
${item.title} <em>by ${item.author}</em>
Me.java
public static void add(String title) {
//add the item
return render("anitemtemplate", newitem); //how to do this??
}
오류가 무엇이어야 하는가? render에 전달 된 변수는 항상 같은 이름을 가지므로'render ("anitemtemplate", item)'이어야합니다. – maartencls