1. #1
    Sencha User jlyman's Avatar
    Join Date
    Nov 2010
    Posts
    28
    Answers
    4
    Vote Rating
    0
    jlyman is on a distinguished road

      0  

    Default Answered: Using a composite value for displayField

    Answered: Using a composite value for displayField


    Been trying to come up with a way to display a composite field, or a returned value, on select fields, instead of just one field from a model. For example, if I have a store of User models, and each User entry has a firstName field and a lastName field, I would like to have a select field that gives me "firstName lastName" as the options, instead of just one or the other. The resulting display value would either be the combo of two fields, or ideally, the return value of a method (in the model or elsewhere).

    I couldn't see a way to do this with displayField based on how the source is grabbing the value, so I'm assuming it would have to be done with something a little more tricky. Anybody come up with a good, generalizable way of doing this?

  2. What you could do is create a field in your Model definition with a custom convert method. In this method you get passed the record and you can return any value. Here you could concatenate firstName + lastName into an aggregate field and use that as the displayField.

    Let me know if that explanation didn't make any sense

  3. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Answers
    28
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    What you could do is create a field in your Model definition with a custom convert method. In this method you get passed the record and you can return any value. Here you could concatenate firstName + lastName into an aggregate field and use that as the displayField.

    Let me know if that explanation didn't make any sense

  4. #3
    Sencha User jlyman's Avatar
    Join Date
    Nov 2010
    Posts
    28
    Answers
    4
    Vote Rating
    0
    jlyman is on a distinguished road

      0  

    Default


    Thanks Tommy, that does make sense. I found the documentation for the convert method (http://docs.sencha.com/touch/2-0/#!/...ld-cfg-convert) but the code example seems to not be in the full MVC format, and I don't know how to address the convert method if I place it within the User model. For example, my model might look like

    PHP Code:
    Ext.define('MyApp.model.User', {
        
    extend'Ext.data.Model',
            
    config: {
            
    fields: [
                {
    name'firstName'type'string'},
                {
    name'lastName'type'string'},
                {
    name'fullName'type'string'convert'fullNameConv' }
            ],

            
    proxy: {...}
        },
            
    fullNameConv: function (vrecord) {
            return 
    record.firstName ' ' record.lastName;
        }
    }); 
    What would be the proper way to address that fullNameConv method? (As written doesn't work, of course).

  5. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Answers
    28
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Unfortunately you can't just use a function name string. This is only supported in Controllers and Components in listener/control blocks. You will have to add that function as a static method on a singleton (MyApp.utils.fullNameConvert) or just add the function inline.

    I don't think its such bad practice to just inline the function in this case. There is no reason that convert function needs to be on the prototype on the Model (other then because it just looks better ).

  6. #5
    Sencha User jlyman's Avatar
    Join Date
    Nov 2010
    Posts
    28
    Answers
    4
    Vote Rating
    0
    jlyman is on a distinguished road

      0  

    Default


    Gotchya, and an inline will work just fine there. Thanks for the clarification and great answer!

Thread Participants: 1

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