-2

I create custom button on ListView. Then i create new object, new button has null ID. Please see snipet.

Steps:

  1. Click Create.
  2. Fill edit form.
  3. Click save.
  4. Click options and see alert null;

            save: function(e)
            {
                // What i can do this, if i know id here?
                e.model.id = ids++;
            },
    
nim
  • 357
  • 1
  • 5
  • 16

1 Answers1

0

Typically id is returned by the server but in your example where the DataSource is a local object you can manually assign it but you should assign it to the id not to id. I.e.: in your model definition the id is code (not id) so save function should be:

save: function(e) {
    e.model.code = ids++;
},

Your snippet modified here

OnaBai
  • 40,767
  • 6
  • 96
  • 125
  • Your snipet is work but my project not worked. Please see some screens: http://prntscr.com/5iogss http://prntscr.com/5iohwx http://prntscr.com/5ioip9 http://prntscr.com/5ioj8i – nim Dec 19 '14 at 19:31
  • I found problem. in save function i make async ajax request, to store data on server. If i make sync request it,s ok. How i can use async ? – nim Dec 19 '14 at 21:18
  • Why do not implement the `update` method in your `datastore` definition? Then, when the ajax async call finished you invoke `op.success` with the argument that is the object with the final `id` (note: `op` is the argument of your `update` method). – OnaBai Dec 19 '14 at 21:20
  • You mean rebuild datasource and interface? – nim Dec 19 '14 at 22:10
  • Can you get any link for a similar example. I probably want a lot, but I strive to write code more competent. – nim Dec 19 '14 at 22:30