Jacob
Jacob

Reputation: 4021

Ext Js proxy pass parameter

I want to pass a parameter to my Store proxy to retrieve the right data from the server. I need to pass the parameter without the name prefix and just the value.

Instead of this kind of url :

myAppUrl/collections/units?collectionId=54

which can be done like this:

myStore.getProxy().extraParams.collectionId = 54;

I want to have a call like this:

myAppUrl/collections/54/units

My web service is adapted for both calls I just need the correct client code to pass the parameter.

Please help and advise.

Upvotes: 1

Views: 3504

Answers (3)

Alfonso Nishikawa
Alfonso Nishikawa

Reputation: 1885

An old question, but I write for anyone with this problem. I implemented the idea of @Saki in this package (for ExtJS 6) because of my own needs:

https://bitbucket.org/alfonsonishikawa/extjspackages/wiki/Server%20URL%20Placeholders

The idea is being able to use an URL like:

proxy: {
  type: 'rest',
  url: 'myAppUrl/collections/${collectionId}/units',
  appendId: false
}

With that package, you just have to configure your proxy like above and call #load() with params:

store.load({
  params: {
      collectionId: 54
  }
});

(getProxy().extraParams can be used as default value)

This is the source code as example that you asked @Saki about.

Upvotes: 2

Naresh Tank
Naresh Tank

Reputation: 1568

you can set your url dynamically and then call load method of store using below code.

store.getProxy().setUrl('your new url');
store.load();

but if you gonna use this method then you have to set correct url every time other-vice may be you will get wrong data.

Upvotes: 0

Saki
Saki

Reputation: 5856

It looks almost like REST request but not exactly as REST places indexes at the end of url. You could solve it by implementing a custom buildUrl of Ajax or Rest proxy. In any case, see how is this method implemented in Rest proxy.

Upvotes: 1

Related Questions