Threaded View

  1. #1
    Sencha User cyberwombat's Avatar
    Join Date
    Oct 2011
    Posts
    237
    Answers
    6
    Vote Rating
    2
    cyberwombat is on a distinguished road

      0  

    Default Answered: How to get a single model

    Answered: How to get a single model


    I would like to input on how to best handle a situation. I have a store of users and a corresponding user model. The proxies for each are different - I assume Sencha will use the store proxy when I need a collection and the model proxy when I just need one?


    In my app I sometimes need to get a user that may not be in my current store collection. So I want to download it directly and add it to the store. Unsure how to do this.


    User model:
    Code:
    Ext.define("App.model.User", {
        extend: "Ext.data.Model",
        config: {
            fields: ['id', 'name'],
            proxy: {
                type: 'ajax',
                url : config.url + "/user",
                reader: 'json'
            },
        }
    });



    Users store:
    Code:
    Ext.define("App.store.Users", {
        extend: "Ext.data.Store",
        requires: "App.model.User",
         config: {
             autoLoad: true,
             model: "App.model.User",
             proxy: {
                type: 'ajax',
                url : config.url + "/users",
                reader: 'json'
            }
        }
    });

    In my controller code - this doesn't work
    Code:
    var d = Ext.data.StoreManager.lookup('Users');
    var e = d.find('id', 'someid');
    if(e == -1) {
        Ext.ModelManager.getModel('User').load('someid');
    }

    Errors are get:
    Uncaught Error: [ERROR][Ext.data.Operation#setModel] An Operation needs to have a model defined. (if I try to call load on store instead of find)
    Uncaught TypeError: Cannot call method 'load' of undefined (if I try to use modelmanager)




    So how can I fetch a user by id from store and have the model automatically fetch it from proxy if not found?


    Thanks


Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi