call two web services from one store in sencha touch

110 views Asked by At

I want to call two web services from one store and want to bind them with a listview in sencha touch.

For example, I have two web services which are as follows:

   1.  Company 
        comp_id
        comp_name
        emp_id

   2.  Employee
       emp_id
       emp_name

Both of the services have different urls and I have to use these services separately as I don't have control over a customer's database.

So now I want to create one or two models & one store for these two webservices, so that I can simply bind it with the lisview and show it in sencha touch.

But the issue is that store has a proxy which can fire only one request at a time. How can I aggregate it in a model and display it in a list view ?

1

There are 1 answers

0
OhmzTech On

Disclaimer: You shouldn't do it this way. It just doesn't make sense. Models, stores, and dataviews are meant to operate a certain way. By breaking this concept too often you will only be kicking yourself later on when things get more complex.

With that said, I still understand the reasoning and here are some ideas I recommend:

-Normalize the model and dataview templates (use only one model with generic field names). Don't use the store proxies to call the API, instead just do independent Ajax/JsonP requests asynchronously, map the results to the normalized model fields, and add model records to the store. This allows you to add the data from one or more sources as needed, independent of each other.

-Add logic to the proxy on beforerequest. When loading the store, pass custom arguments and handle them in this logic to switch URLs. Then handle results on requestcomplete to set them to the relevant models. You still are faced with the issue though that really one model = one store.

-Consider doing something like the above, except use store associations. One model can be the associated model and you can use the provided relations functions for templating.