简体   繁体   English

使用ng-admin发布到嵌套资源

[英]POST to a nested resource using ng-admin

The documentation shows an example on how to fetch entities on a nested resource ( http://[baseApiUrl]/posts/123/comments ) by using an interceptor on the $http Angular service. 该文档显示了一个示例 ,该示例说明如何使用$http Angular服务上的拦截器来获取嵌套资源( http://[baseApiUrl]/posts/123/comments )上的实体。 I'd like to know how to create entities on nested resources. 我想知道如何在嵌套资源上创建实体。 Is this possible on ng-admin without resorting to custom pages? 是否可以在ng-admin上实现而不求助于自定义页面?

I've been struggling with this some time and found a work around. 我一直在为此苦苦挣扎,并找到了解决方法。 I've also tried your interceptor to fetch child objects of some parent object. 我还尝试过拦截器来获取某些父对象的子对象。 It works. 有用。 But I went back to the embedded_list to make also creation and updating of the parent with the child object in one post/put to the backend. 但是,我又回到了Embedded_list,在一个子对象/后端中创建和更新带有子对象的父对象。 So when fetching /posts/123 I also have the comments in the object. 因此,在获取/ posts / 123时,我在对象中也有注释。 Then, after changing some data I PUT the whole object back. 然后,在更改了一些数据之后,我将整个对象放回原处。 That works. 这样可行。 There are some problems however. 但是有一些问题。 One of them is that 'reference' field types within the embedded_list don't populate properly. 其中之一是,embedded_list 内的 “参考”字段类型不正确填充。 You can work around this by adding the same reference field to the editionView() or creationView() (the level above the embedded_list and set label to '' and cssClasses to 'visibility: hidden'. A very bad solution of course but it does work. I still need to ask this to the developers of ng-admin. 您可以通过将相同的引用字段添加到editionView()或creationView()(在Embedded_list上方的级别并将label设置为”,将cssClasses设置为“ visibility:hidden”)来解决此问题。我仍然需要向ng-admin的开发人员询问。

So I now try to use embedded_list as much as possible to be able to put and post objects with child elements in one call to the backend. 因此,我现在尝试尽可能多地使用Embedded_list,以便能够在对后端的一次调用中放置和发布带有子元素的对象。

Does this help? 这有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM