*更新:请参阅下面最后一个代码块中的最终答案代码.*
目前,我在集合视图中显示集合时遇到问题.该集合是现有模型的属性,如此(伪代码)
ApplicationVersion { Id: 1, VersionName: "", ApplicationCategories[] }
Run Code Online (Sandbox Code Playgroud)
所以基本上ApplicationVersion有一个名为ApplicationCategories的属性,它是一个javascript数组.目前,当我渲染与ApplicationCategories相关联的集合视图时,不会呈现任何内容.如果我在Chrome的javascript调试器中调试,似乎尚未填充类别(因此我假设还没有提取ApplicationVersion).这是我目前的代码
ApplicationCategory模型,集合和视图
ApplicationModule.ApplicationCategory = Backbone.Model.extend({
urlRoot:"/applicationcategories"
});
ApplicationModule.ApplicationCategories = Recruit.Collection.extend({
url:"/applicationcategories",
model:ApplicationModule.ApplicationCategory,
initialize: function(){
/*
* By default backbone does not bind the collection change event to the comparator
* for performance reasons. I am choosing to not preoptimize though and do the
* binding. This may need to change later if performance becomes an issue.
* See https://github.com/documentcloud/backbone/issues/689
*
* Note also this is only nescessary …Run Code Online (Sandbox Code Playgroud) 我正在创建一个基本的POST JSON api端点.我想对它进行单元测试,并希望确保我在Play框架中正确地进行测试.到目前为止,我使用Guice进行依赖注入,使用JUnit进行单元测试库.
这是我的控制器代码:
public class NotificationController extends Controller {
private RabbitQueueService _rabbitQueueService;
@Inject
public NotificationController(RabbitQueueService service) {
_rabbitQueueService = service;
}
@BodyParser.Of(BodyParser.Json.class)
public Result post() {
ObjectMapper mapper = new ObjectMapper();
Notification notification;
try {
JsonNode notificationJsonNode = Controller.request().body().asJson();
notification = mapper.readValue(notificationJsonNode.toString(),
Notification.class);
_rabbitQueueService.push(notification);
return Results.created(notificationJsonNode, "UTF-8");
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return Results.badRequest();
}
}
Run Code Online (Sandbox Code Playgroud)
我的RabbitQueueService代码:
public class RabbitQueueService {
private Channel _channel;
private …Run Code Online (Sandbox Code Playgroud) java unit-testing dependency-injection playframework playframework-2.2