cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Update local json model

Former Member
0 Kudos

Hi All,

I have a json model like this:


{

  "customers" : [

      {"name" : "Joe", "surname" : "Black"},

      {"name" : "Jesse", "surname" : "James"},

      ...

  ]

}

I display the customer details in the below list, where the user can also edit the customer:


this.list =

new sap.m.List({

  items : [        

          new sap.m.InputListItem({

               label : "Name:",

               content : new sap.m.Input("name", {

               type : "Text",

               placeholder : "Name",

               value : "{name}"

               })

          }),

          new sap.m.InputListItem({

               label : "Surname:",

               content : new sap.m.Input("surname", {

               type : "Text",

               placeholder : "Surname",

               value : "{surname}"

               })

          })

  ]

  });

Once the user has changed the displayed info, how can I save the changes?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi there,

approximately I have the same problem.


The entire roundtrip should look like this:

  1. the app shows the entire list of products
  2. user clicks on product in the list
  3. the app takes the user to the detail view, where all the details for the product are shown (do a read on the oModel with filter string - list.bindaggregation (displaylistitem)
  4. user can click on product change button and app will slide to another view (input) where he can change the propertys.
  5. user edits the name of the product and press "save edits"
  6. oModel.update()

I'm looking for a code example especially for the update- and create-method with json-Model.

I have already seen a couple of blogs and posts here on the scn, but nothing could help me.

I don't know how to fetch the x-csrf-token from a oModel.read-method. (I tried with response.headers in the onReadSuccess-function)

I don't know how to handle the request in the update-entity-method in where I can CALL FUNCTION 'ChangeProduct' for example. (I think I will get import-parameters?)

I'm looking forward anybody can help me.

Thx very much,

Tobias

former_member182372
Active Contributor
0 Kudos

Tommaso, what is the layout you are trying to implement? If you use binding for sap.m.List you can define only one template of sap.m.InputListItem with property bound to the same model property (value->{name}) not 2

Former Member
0 Kudos

Hi Maksim,

yes I'm sap.m.List to display the customer detail. I'm using a local object, the List is bounded to that object to show the customer detail and I'd like to know if it's possible and how to update a value for a customer. The entire roundtrip should look like this:

  1. the app shows the entire list of customers
  2. user clicks on customer number two in the list (Jesse James)
  3. the app takes the user to the detail view, where all the details for Jesse James are shown
  4. user edits the date of birth for Jesse James and press "save edits"
  5. the edits are saved on the current model

Is it possible? How?

Thank you in advance

ps: do you guys have or can you please link me to a complete code example for CRUD operations?

former_member182372
Active Contributor
0 Kudos

smth like this ?

List-Detail

Former Member
0 Kudos

that's very helpful, thank you Maksim!