Results 1 to 8 of 8

Thread: How do I bind a view to one specific record?

  1. #1
    Sencha User
    Join Date
    Jan 2014
    Posts
    14

    Default How do I bind a view to one specific record?

    I have a model that is a user's own profile, things like First Name, Last Name, etc.

    It loads using a proxy using an HTTP request.

    I have a view that basically displays the user's profile.

    I want to bind this one record/model to this view using a view model, how do I do this?

    If I use the link config option, it makes a separate HTTP request to request its own version of the user. This doesn't work because changes to the main record don't update to this separately fetched record.

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,254
    Answers
    759

    Default

    Assuming you already have the record reference, just add it as part of the data:

    Code:
    data: {
        theUser: rec
    }
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha User
    Join Date
    Jan 2014
    Posts
    14

    Default

    Quote Originally Posted by evant View Post
    Assuming you already have the record reference, just add it as part of the data:

    Code:
    data: {
        theUser: rec
    }
    Thanks, I realized I need to use viewModel.linkTo('user', profile); where profile is the record since the record isn't created yet when the view is created.

    This works, but when the record changes nothing happens, its stuck at the initial values of the record. How do I fix this?

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,254
    Answers
    759

    Default

    I'm not really clear on what you're saying. Do you mean the when the record reference changes, or when a field value changes?
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  5. #5
    Sencha User
    Join Date
    Jan 2014
    Posts
    14

    Default

    The record reference is the same, but when a field value in that record changes it doesn't update the view. I'll see if I can put together a Fiddle to show you.

  6. #6
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,254
    Answers
    759
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  7. #7
    Sencha User
    Join Date
    Jan 2014
    Posts
    14

    Default

    Quote Originally Posted by evant View Post
    Cool, thank you, what if I don't have a reference to the record when the view is created, can I link the record to the viewModel when I do have the record created after?

  8. #8
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,254
    Answers
    759

    Default

    Yes, just call:

    Code:
    vm.set('theUser', rec);
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Similar Threads

  1. Replies: 2
    Last Post: 29 Oct 2014, 4:02 AM
  2. get specific bind value for component
    By daly in forum Ext 5: Q&A
    Replies: 1
    Last Post: 23 Sep 2014, 7:16 PM
  3. setCls to a specific record on a list
    By Tioecomp in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 13 Dec 2012, 5:50 AM
  4. Load Specific Record from Store Into A View (template)
    By dboy221 in forum Sencha Architect 2.x: Help & Discussions
    Replies: 21
    Last Post: 26 Oct 2012, 6:45 AM
  5. Bind an event to components of a specific type
    By strictlyphp in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 1 Sep 2010, 11:57 PM

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
  •