ExtJs: find a record, edit and post changes

29 Views Asked by At

i'm learning ExtJs.

I'm trying to accomplish a very easy task: find a record, edit data and post changes back.

I have defined the model class with the correct proxy.

Now my code is like this:

        const amodel=Ext.create('TestApp.model.theModel');

        amodel.set('id','001');

        amodel.load({
            success(rec) {
                // Ok, i have found the data

                rec.set('aField',rec.data.entity.aField+' MODIFIED'); // Update the field

                rec.save({ // Exception returned by the server cause data sent is not correct
                    success(rec) {
                      // The record has been updated      
                    }
                });
            }
        });

What's my mistake ?

thanks

Roberto

2

There are 2 best solutions below

3
Roberto Nicchi On

I have found the problem. Changed my code as follow:

rec.set('aField',rec.data.entity.aField+' MODIFIED'); // Replaced by the following code

rec.data=rec.data.entity;
rec.set('aField',rec.get('aField')+' MODIFIED');
0
Dinkheller On

In the comments you asked for Fiddles. Here is the answer, plus some ideas about your code.

It might be a good idea to setup a fiddle:

fiddle.sencha.com

You need credentials from

https://forum.sencha.com/forum/register.php

Once you created your own fiddle, try to work with getter and setter.

@Example

rec.set(rec.get('entity')).

rec.set will fire an event from the model AND inform the store that you changed the record. Plus it will change rec.data accordingly.

Hint

ClassNames should be uppercase, e.g. 'TestApp.model.TheModel'

TestApp  Appname   (is PascalCase)
model    Directory (are lowercase)
TheModel Classname (FileNames and ClassNames are PascalCase)