Closed tepsl closed 8 years ago
Hello! Thank you for report it. I need to reproduce to fix it, can you share an example please?
I have tried gs.toGroovy({remove: 'remove'}) and gs.toGroovy('remove') without success.
Sorry for late reply. My code is almost based on http://grooscript.org/grails3-plugin/ The grails version is 3.0.9.
Add dependencies:
dependencies {
...
compile "org.grails.plugins:grooscript:1.1.2"
runtime "org.grails.plugins:jquery:1.11.1"
...
}
Add domain class:
package grooscript_sample
import grails.rest.Resource
@Resource(uri='/books')
class Book {
String title
String author
static constraints = {
author nullable: true
}
}
Edit Bootstrap.groovy:
import grooscript_sample.Book
class BootStrap {
def init = { servletContext ->
new Book(title:'First Book').save()
new Book(title:'Second Book', author:'some author').save()
}
def destroy = {
}
}
Edit view/index.gsp:
<!DOCTYPE html>
<html>
<head>
<title>Rest grooscript demo</title>
<asset:javascript src="jquery-2.1.3.js"/>
<asset:javascript src="grooscript-grails.js"/>
</head>
<body>
<grooscript:remoteModel domainClass="Book"/>
<h2>List of books</h2>
<div id="bookList"/>
<grooscript:code>
import grooscript_sample.Book
def drawBooks = {
Book.list().then { list ->
$('#bookList').html ''
list.each {
$('#bookList').append('<p>Title: '+it.title+' - Author: '+ (it.author?: 'unknown') +'</p>')
}
}
}
$(document).ready {
drawBooks()
}
</grooscript:code>
<asset:deferredScripts/>
</body>
</html>
Then start grails and open http://localhost:8080/ No book is listed and JavaScript error is shown in developer console.
I got it, the problem is the documentation. Not enought clear, that you have to use JSON and not xml. The client expects json from the server. I'm going to update the documentation.
@Resource(uri='/books', formats=['json'])
Thank you very much for report it :)
Got it working! Thanks.
Cheers thank you! In time for the new release 1.1.3
In grooscript-grails.js, an exception occurs because result.add is undefined when ob == 'remove'.