Results 1 to 5 of 5

Thread: How to pass data to a view model in a linked component?

  1. #1
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,337
    Answers
    13
    Vote Rating
    418
      0  

    Question How to pass data to a view model in a linked component?

    I've created a panel with its own view model/controller that I've linked to another form (by drag and drop in Sencha Architect 3.2). How do I go about binding values from the view model of the parent form so that the linked panel can see them? I don't even know where to begin tackling this one. Here's my linked component config on the parent form:

    Code:
    {
        xtype: 'fieldset',
        layout: 'auto',
        title: 'Submit to Supervisor',
        items: [
            {
                xtype: 'approvalpanel', // this is the userAlias of the linked component
                width: 450
            }
        ]
    }
    I need the get the value of a field from a linked model instance of the parent form, from within the 'approvalpanel' and use that value to change the URL of a store's proxy.

  2. #2
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,337
    Answers
    13
    Vote Rating
    418
      0  

    Wink

    I didn't fully appreciate that child components get to see stuff from their parent view models automatically. I was able to do this in the linked component's afterRender() event:

    Code:
    var vm = this,
        store = vm.getStore('Managers'),
        proxy = store.getProxy(),
        record = vm.getData().record, // this is the linked record from the parent form
        user_guid = (record.phantom) ? App.global.user_guid : record.get('user_guid');
    
    proxy.url = '../Service/Employees/' + user_guid + '/Managers/';
    store.load();

  3. #3
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,337
    Answers
    13
    Vote Rating
    418
      0  

    Default

    This works well for configuring stores based on a value in the parent view model, but now I've hit another bit of a snag. I want to set a field in a linked record of the parent view model when the combobox selected value changes in the linked component. I could probably do this in the linked component, but that's hard-coding a value in the parent record/field that I don't want to do:

    Code:
    this.get('linkedRecordNameInParent').set('fieldName', 'value');
    The whole reason I created the component separately was so that I could use it in several places without it having to know the name of the linked record and field in which to set the selected value from the combobox.

    What's the "correct way" to handle this? Is there a way the parent component can look for a common reference/binding/whatever and use that to set the value of a field in a linked record?


    Being a Sencha Architect thread, I'm probably having a conversation with myself, but I'll try my luck.

  4. #4
    Sencha Premium Member
    Join Date
    Jan 2010
    Location
    Vancouver, Canada
    Posts
    214
    Answers
    2
    Vote Rating
    71
      0  

    Default

    Did you ever find an answer to your last post?

  5. #5
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,337
    Answers
    13
    Vote Rating
    418
      0  

    Default

    Quote Originally Posted by bogc View Post
    Did you ever find an answer to your last post?
    It's been a while now but I think I ended up just compromising and going with a hard-coded reference and made sure I added comments where ever I used it to inform any other poor soul who might have to look at my code one day. I had plans to really abstract that particular component and re-use it everywhere but I decided against that, given that hard-coding I would have needed.

    Having said that, now that I think about it some more, I suppose might be able to viewmodel.set() a property which exists in the parent view model (and not in the child), and it might therefore end up setting it higher up where it belongs rather than creating it on-the-fly in the child/linked component?

Similar Threads

  1. Replies: 2
    Last Post: 14 Apr 2015, 11:21 PM
  2. Boolean field in Model pass false value to view
    By ramya.gopalan in forum Ext: Q&A
    Replies: 2
    Last Post: 24 Jul 2014, 9:47 AM
  3. How to pass data from one view to another view
    By deepackm in forum Ext: Q&A
    Replies: 1
    Last Post: 16 Jul 2013, 11:58 AM
  4. How to pass data from a view to a model.
    By wuytsr in forum Sencha Touch 2.x: Q&A
    Replies: 2
    Last Post: 26 Nov 2012, 8:04 AM

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
  •