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 Unanswered: hasMany association and tpl for only shows 1 record

    Unanswered: hasMany association and tpl for only shows 1 record


    Alright, this one's been bugging me for a little while now and I can't seem to find what I'm doing wrong. Hoping that someone in the community can point out my error.

    I have a view with an XTemplate in it as follows (simplified):

    PHP Code:
            store'ReviewNotifications',
            
    itemTpl: new Ext.XTemplate(
                
    '<h1 class="note-title">{title}</h1>',
                
    '<tpl if="questions.length &gt; 0">',
                    
    '<h3 class="review-questions-title">Review Questions</h3>',
                    
    '<tpl for="questions">',
                            
    '<div id="reviewq{id}_prompt" class="reviewq-prompt">{#}. {prompt}</div>',
                    
    '</tpl>',
                
    '</tpl>'
            

    This is driven by two different models, Notification and NotificationReviewQuestion, which are set up and appear to be working properly as evidenced by their correct use in other parts of the application (again simplified):

    PHP Code:
    Ext.define('Intuiplan.model.Notification', {
        
    extend'Ext.data.Model',
            
    config: {
            
    fields: [
                { 
    name'id'type'int' },
                { 
    name'title'type'string' },
            ],
            
            
    hasMany: { model'Intuiplan.model.NotificationReviewQuestion'name'questions'associationKey'questions' }
        }
    }); 
    PHP Code:
    Ext.define('Intuiplan.model.NotificationReviewQuestion', {
        
    extend'Ext.data.Model',
            
    config: {
            
    fields: [
                { 
    name'id'type'auto' },
                { 
    name'notification_id'type'int' },
                { 
    name'prompt'type'string' },
                { 
    name'correct'type'int' }
            ],
               
           
    belongsTo'Intuiplan.model.Notification'
        
    }
    }); 
    The template renders correctly except that it will only render the first of any NotificationReviewQuestions that are present, even when multiple are associated and in the store. When I console.log all the models, I can explore them and see that the associations are there and that the stores are storing the models and associations properly. Other parts of the app cycle through all of the related ReviewQuestions as well, so I know that it is pulling in the data correctly.

    What am I doing wrong in my template that is causing it to only show the first relation? Thanks so much for any pointers all!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Answers
    3356
    Vote Rating
    751
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Does the one question that is displayed have the correct data?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #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


    Yes.

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Vote Rating
    0
    L1Blom is on a distinguished road

      0  

    Default Have the same issue

    Have the same issue


    I have the same issue: <tpl for="sub"> shows only one record. The raw data is complete, but the data in subs contains one record (Array[1]). In my case a subsubmodel shows all records! It's the first model below the main model of an association that fails...

  5. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    1
    Vote Rating
    0
    goncalo is on a distinguished road

      0  

    Default


    +1

    I've exactly the same issue !

    Anyone ?

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

      0  

    Default


    Ya, bump, still having this issue.

  7. #7
    Sencha User
    Join Date
    Aug 2011
    Location
    Cedar Rapids, IA
    Posts
    63
    Answers
    8
    Vote Rating
    1
    aoathout is on a distinguished road

      0  

    Default


    Have you tried the following: http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Model-method-getData

    I had an issue that sounds a lot like what you are seeing and I got around it passing true to the models getData(). I only have to-do this when I load my records from localstorage, I don't have to-do this when I pull from the server. Maybe this will work for you as well.

    Code:
    // Function finds the component that will show the data and binds the 
    // records data to it so the tpl can display it and its associations.
    setRecordToDisplay: function(record) {
         this.getComponent('somecomponent').setData(record.getData(true));
    }

  8. #8
    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 for the suggestion aoathout, but that didn't seem to be my problem, as it is occurring when I pull in data for a whole store, not just individual records.

    Upon further investigation, this is what I'm seeing when I console.log the objects (and using the same model code as provided in the original post). As a reminder, I expect a Notification object to have many NotificationReviewQuestions, available via .questions().

    When inspecting the Notifications object from a console.log(), I see the following properties:
    • _data: contains all of the correct first level data for Notification, and a key called "questions" with 1 element in it, the first NotificationReviewQuestion object that I'd expect (but not the second+ one).
    • data: Same thing as _data, just the first NotificationReviewQuestion under questions.
    • questionsStore: Now here, under _data>all and data>all I see all the NotificationReviewQuestion objects I'd expect to see! So I know that the data is getting in and interpreted somehow, but maybe I'm accessing it incorrectly. Also to note, even though I've set a storeId manually in my NotificationReviewQuestions store, this particular store's _storeId is set to "ext-data-store-1" but I'm not sure if that matters.
    Also, in my controller after I load the Notifications object, I iterate over the questions that I'd expect in the object by doing record.questions().each() and sure enough, it pulls and recognizes all the multiple NotificationReviewQuestion objects. But when I use the template code like I have above, it is only using that first object, I assume because that is all that is available in data>questions.

    Does that provide more info that someone could work with? I am sure I'm probably just accessing something incorrectly, but can't see what. Thanks for any help, gotta get this fixed!

  9. #9
    Sencha User
    Join Date
    Apr 2012
    Posts
    3
    Vote Rating
    1
    jdesjean is on a distinguished road

      0  

    Default


    I have the same problem.

  10. #10
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    604
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    The idProperty for models has to be of type auto. So primary and foreign keys will be generally of type auto in definitions.

    PHP Code:
    Ext.define('Intuiplan.model.Notification', {
        
    extend'Ext.data.Model',
            
    config: {
            
    fields: [
                { 
    name'id'type'auto' },
                { 
    name'title'type'string' },
            ],
            
            
    hasMany: { model'Intuiplan.model.NotificationReviewQuestion'name'questions'associationKey'questions' }
        }
    }); 

    PHP Code:
    Ext.define('Intuiplan.model.NotificationReviewQuestion', {
        
    extend'Ext.data.Model',
            
    config: {
            
    fields: [
                { 
    name'id'type'auto' },
                { 
    name'notification_id'type'auto' },
                { 
    name'prompt'type'string' },
                { 
    name'correct'type'int' }
            ],
               
           
    belongsTo'Intuiplan.model.Notification'
        
    }
    }); 

    I would debug what happens in tempolate like this:

    PHP Code:
            store'ReviewNotifications',
            
    itemTpl: new Ext.XTemplate(
                
    '<h1 class="note-title">{title}</h1>',
                 
    '[{console.log(values)}]',
                 
    '[{console.log(values.questions)}]',
                 
    '[{console.log(values.questions())}]',
                
    '<tpl if="questions.length &gt; 0">',
                    
    '<h3 class="review-questions-title">Review Questions</h3>',
                    
    '<tpl for="questions">',
                            
    '<div id="reviewq{id}_prompt" class="reviewq-prompt">{#}. {prompt}</div>',
                    
    '</tpl>',
                
    '</tpl>'

    Please let me know what you get listed in console

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar