1
votes

I have two stores:

  • FAQs - contains a lot of models of my items
  • FAQ - contains one model.

In view mode I work with FAQs (to see all items) and in edit mode I work with FAQ just to work with one item and not to load all of them.

After finishing editing and saving FAQ I need to find that item in FAQs and make changes there as I've made in FAQ. I don't use network for it.

I know two ways:

1) find needed record in FAQs and replace it there

_updateFaqsStore: function() {
   var faqsStore = Ext.data.StoreManager.lookup("faqs.FAQs");
   var activeRec = this.activeRecord;
   var index = faqsStore.indexOf( faqsStore.findRecord('id',activeRec.get('id')) ); // index in faqsStore of activeRec
   faqsStore.remove(faqsStore.findRecord('id',activeRec.get('id'))); // remove old rec
   faqsStore.insert(index, activeRec); // insert new - activeRec

but the object structure is not the same (though I use the same model)

2) find needed record in FAQs and set there every field

    var faqsItem = faqsStore.findRecord('id', activeRec.get('id')); // find same item in FAQs store
    faqsItem.set("myField", activeRec.get('myField')); // make changes in FAQs as in FAQ

but I need to enumerate all fields.

Maybe, there is some other way out? Please, help me!

1
What does it mean I don't use network? Where do you get those data's?Oğuz Çelikdemir
I meant that for my updating one store's record from another I don't need internet. But I use i-net for getting all the data and saving it laterIvan
Then, why don't you use store reload function after record update!Oğuz Çelikdemir
I need to minimize requests to server. Just to exchange data between those two storesIvan

1 Answers

0
votes

You should not use two stores in this case. Why aren't you just using one store FAQs ? You then select the record, and you edit it directly.

For your use case there is no need at all to use two stores.

Also, you say you need to minimize the number of requests to the server. There is no problem for this. Just edit all the records you need to, and the at the end, you save all to the server at once.

Look at this example : it shows how to edit a record in a separate form, how to configure your requests (autoSync and batch buttons). You will deactivate autoSync and use batches to minimize roundtrips to the server.

Look also at rowediting example. This allows you to edit the data even easier.