1. #1
    Sencha User
    Join Date
    Nov 2012
    Location
    London, UK
    Posts
    17
    Vote Rating
    1
    Answers
    1
    chrigil is on a distinguished road

      0  

    Default Answered: How to set DataView's Store to be model's associated Model?

    Answered: How to set DataView's Store to be model's associated Model?


    I have a dataset loading via JSON into a Store which is represented by 3 models. The models pretty much exactly reflect the structure of the JSON as such I have the following:

    JSON:
    Code:
    {
       "Client":{
          "Id":"123456",
          "Title":"Mr",
          "FirstName":"Joe",
          "Surname":"Blogs",
          "Booking":[
             {
                "BookingNodeId":123456,
                "Origin":"London",
                "Destination":"Paris"
             },
             {
                "BookingNodeId":1234567,
                "Origin":"London",
                "Destination":"Dubai"
             },
             {
                "BookingNodeId":12345678,
                "Origin":"London",
                "Destination":"Tokyo"
             }
          ],
          "Contact":[
             {
                "Name":"Steve",
                "PhoneNumber":"08001231234"
             }
          ]
       }
    }
    Models:
    Code:
    Client:
        Id, Title, FirstName, Surname
        HasManyAssociation: Booking
        HasManyAssociation: Contact
    
    Booking:
        BookingNodeId, Origin, Destination
    
    Contact
        Name, PhoneNumber
    Store:
    Code:
    ClientStore
        JSONReader loads the JSON and has implicitIncludes set meaning that the Client, Bookings and Contacts models are all loaded and setup at the same time (which is exactly what I want).
    If I set the Store property of my DataView to be the ClientStore, everything works fine provided I set the properties in my DataViewTemplate to be Client.Booking.Origin for example.

    What I want to know is how I can set the Store of my DataView to be a sub-model of my Client model. For example how would I set it so that the Bookings were the items that are bound to the DataView?
    do I need to set up another Store or do I need to refactor in some other way?

    Thanks

    Chris

  2. If you have a hasMany association then it will create a store to hold the records so you would have to use that store on the dataview.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,714
    Vote Rating
    436
    Answers
    3113
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    If you have a hasMany association then it will create a store to hold the records so you would have to use that store on the dataview.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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