1

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.

1
  • Can you review the answers? :) Thank you! Commented May 16, 2018 at 18:45

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

3 Comments

Could you provide a simple example
I haven't (yet) had the requirement of a custom URL such as yours so I don't have any working example I could share with you. The thing is simpler than it looks: You get the request as argument and you return ready made url. The logic in between is also going to be quite simple.
Thanks for the idea, helped me to create the package :)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.