我正在尝试将对象添加到Grails中的JSON列表中。这是我的Angular代码:
http://pastebin.com/4ypijUMD
还有我的Grails Controller :
http://pastebin.com/skTtVtxv
据我了解,我的angularJS脚本应该发送一个请求,以使用列表中最新成员的信息访问添加 Controller 。
然后,add函数应基于从 Angular 脚本和ta-da传递到 Controller 的参数创建一个新的JSON对象。
但是,什么也没有创建,当我尝试更新我的对象时,我只会得到空对象
list with my update controller:
def saveList() {
def newItem = Item.findById(request.JSON.id)
newItem.name = request.JSON.name
newItem.type = request.JSON.type
newItem.priority = request.JSON.priority
newItem.completed = request.JSON.completed
newItem.save(flush: true)
render newItem as JSON
}
最佳答案
您没有显示进行实际AJAX调用的代码,仅显示了带有保存调用的服务。使用Grails和Angular进行此操作的方式如下所示:
$http.post('http://localhost:8080/test-app/myController/addItem', { json values})
.success(function(response) {})
.error(function(response) {});
class MyController {
def addItem() {}
}
关于javascript - 为什么我的Grails应用程序无法从Angular脚本中获取对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30327774/