Kendo MVVM create new record with remote datasource -


I think I'm missing something simple, but I'm not getting any examples of how to do it ... Also, please forgive me if I have some terminology used to be wrong.

I just want to use an HTML form which is bound for a condo observable object to create a new record in my remote data source. / P>

I have seen how to edit existing records in all instances, but this is not what I see (at least not currently).

I have a simple cut-down version of a belt which I have so far received. Obviously this will not really save the record because the URL does not indicate anywhere, but I am confident that I can handle it.

Can anyone tell me in the right direction? Thank you.

And because I can not post a question without it, here are some code that has been copied from the bedel:

  var model = kendo.data.Model Define ({id: "id", field: {id: {type: 'number'}, field 1: {type: 'string'}, field 2: {type: 'string'}, field 3: {type: 'String'}}}); Var viewModel = kendo.observable ({dataSource: new kendo.data.DataSource ({type: 'json', transport: {create: {url: '/ myurl / create', Data type: 'Jason', Type: 'Post '}}, Schema: {data:' data ', model: model}})}}; Kendo.bind ($ ("# my-form"), seeModel);  

We make it a bit different ...

    < Li> Your form does not require objects and objects with DataSource because you did not actually save datasource, but a record.

So, you should define this model:

  var model = kendo.data.Model.define ({id: "id", field) : {Id: {type: 'number'}, field1: {type: 'string'}, field 2: {type: 'string'}, field 3: {type: 'string'}}});  

Datasource becomes per object object now:

  var dataSource = new kendo.data.DataSource ({Type: 'Jason', transport: {Create: "/ mural"}, schema: {model: model}});  

and your objective object has data element defined as model ( new model ()) ).

  var viewModel = kendo.observable ({data: new model), mySave: function (e) {console.log ("this", this.data); data source.add ( This.data); e.preventDefault ();}});  

So, your form should now be something like this:

  & lt; Form id = "my-form" & gt; & Lt; Input name = "field 1" data-bind = "value: data.field1" type = "text" /> & Lt; Input name = "field2" data-bind = "value: data.field2" type = "text" /> & Lt; Input name = "field3" data-bind = "value: data.field3" type = "text" /> & Lt; Button data-bind = "click: my save" & gt; Save & lt; / Button & gt; & Lt; / Form & gt;  

Your JSFiddle modiefied


Comments