Hi.
I'm trying to using CanJS with Play! Framework 1.2.x (http://www.playframework.com/) as backend. Models are defined at backend.
Consider the following code snippets.
Server-side, model Todo:
- public class Todo extends Model {
- public String name;
- }
Client-side:
- <script>
- var Todo = can.Model({
- findAll: 'GET /todos',
- findOne: 'GET /todos/{id}',
- create: 'POST /todos',
- update: 'PUT /todos/{id}',
- destroy: 'DELETE /todos/{id}'
- },{
- });
- var todo = new Todo({name: "pick up cherries and apples"});
- todo.save( function(todo){
- console.log( todo.id, todo.name );
- });
- </script>
I can fetch models from backend using findAll() and findOne() methods successfully. But when I trying to create model I got a problem.
todo.save() sends parameter "name" with value "pick up cherries and apples" to server.
But Play! framework expects that parameter name should be "todo.name" to successfully bind sent data with Todo model.
I can change this behavior on the server-side by prepending parameter name "name" with "todo." but it looks a little messy.
So my question is - can I change this default behavior on the client-side?
--
Best regards,
Pavel Derendyaev