Results 1 to 6 of 6

Thread: Multiple URLs in one Ext.data.Store

  1. #1

    Default Multiple URLs in one Ext.data.Store

    This might be a noobish question but I haven't seen a solution in my searching:

    Is it possible to have multiple URLs in one Ext.data.store so that the different CRUD actions can operate on their corresponding URL? I have build a restful applications that uses the URI and HTTP Request to decide what action to take. For example a GET request to http://www.example.com/path/to/customer.json will return a json object of all customers, while a GET to http://www.example.com/path/to/customer/24.json will return a json object of customer 24. A POST request to http://www.example.com/path/to/customer will add a new customer and a PUT command to http://www.example.com/path/to/customer/24 will update customer 24.

    Here is an example of my store to get the list

    Code:
    store : new Ext.data.Store( {
                    model : 'app.models.Customers',
                    getGroupString : function(record) {
                        return record.get('lastName')[0];
                    },
                    autoLoad : true,
                    proxy : {
                        type : 'ajax',
                        url : '/path/to/customers.json',
                        reader : {
                            type : 'json',
                            root : 'attendeesSet'
                        }
                    }
                })
    I need to be able to perform all CRUD operations on a customer but setting different URLs for each operation. That way I can send the proper request to the proper URI in my restful system and get the desired results.

    Any suggestions?
    Last edited by Mazureth; 4 Oct 2011 at 8:30 PM. Reason: clean up indentation

  2. #2
    Sencha User
    Join Date
    Aug 2010
    Posts
    315

    Default

    Hi, you can set the url in this way:

    Code:
    yourStore.proxy.url = "yourServiceUrl";

  3. #3

    Default Not Quite

    That's not quite what I need. I'm lookin to have multiple URLs associated one store so that the correct the correct one is used when needed. Or are you saying I should change the store URL on the fly when I need to? Is that possible?

  4. #4
    Sencha User
    Join Date
    Aug 2010
    Posts
    315

    Default

    Quote Originally Posted by Mazureth View Post
    Or are you saying I should change the store URL on the fly when I need to? Is that possible?
    That is, the above code is intended to be used on the fly.

  5. #5
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371

    Default

    I needed the same when i used list who call different JsonFile for each Item for create a new List
    different Jsonfile was call with extraParams.
    I explain:

    in my controller:
    Code:
    showDirectoryCategoryList: function(options) {
    		var data = options.data;
    		WPApp.views.DirectoryCategoryListPanelToolbar.setTitle(data.NAME);
    		Ext.getStore(WPApp.stores.DirectoryCategoryListStore).setId(data.ID);
    		WPApp.views.DirectoryPanel.setActiveItem(WPApp.views.DirectoryCategoryListPanel, {type: 'slide'});
    	},
    I set an ID, each Item of my list have an ID.
    After in my Store:
    Code:
    WPApp.stores.DirectoryCategoryListStore = new Ext.data.Store({
    	model: "WPApp.models.DirectoryCategoryListModel",
    	storeId: 'DirectoryCategoryListStore',
    	proxy: {
    		type: 'ajax',
    		url: "/getCategoryList.php",
    		reader: {
    			type: 'json'
    		},
    	},
    	setId: function (id) {
    	    this.itemId = id;
    		WPApp.stores.DirectoryCategoryListStore.load({params:{id:this.itemId}});
    	},
    	autoLoad: true
    });
    With that, it's the same like if i send the URL:
    HTML Code:
    url: "/getCategoryList.php?id=1"
    if i tap on Item 1
    And you can make a good treatment with $_GET in php for each item, call the good request or JSON File.


    It's only a way, i think, there is better, i just do like that and it's working.

    Hope this help you

  6. #6

    Default

    Quote Originally Posted by steve1964 View Post
    That is, the above code is intended to be used on the fly.
    This appears to be the only way to do this, which means in an MVC application the controller is responsible for changing the URL on the proxy. IMO this is bad design as the controller should not have to know the implementation of the store, or even that an ajax proxy is being used (it may be a memory store, local storage, etc.) It seems to me that a better store class is needed with the ability to have multiple URLs as I see this as a very standard approach. One other possibility is to add methods on the store that at least hide the implementation of changing the URL, so perhaps the controller could call store.setUpdateMode() or something like that. Still not sure I like that either though.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •