Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Viewmodel links config

  1. #1
    Sencha User
    Join Date
    Sep 2014
    Posts
    39
    Answers
    2
    Vote Rating
    7
      2  

    Default Viewmodel links config

    Does anyone know where I can find better documentation on the links config in a view model? I would like to store a single model in my view model to be used with my view. The links config sound's like it will do what I want, but I can't find any documentation thoroughly explaining how it works. I also need to set the id dynamically, and load the model based on a user selection.

  2. #2
    Sencha User
    Join Date
    Sep 2014
    Posts
    39
    Answers
    2
    Vote Rating
    7
      1  

    Default

    Still very lost with the links / data configs and how / when to use them.

  3. #3
    Sencha User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,099
    Answers
    734
    Vote Rating
    969
      -2  

    Default

    Can you elaborate about what you don't understand from the docs here:

    http://docs.sencha.com/extjs/5.1/5.1...odel-cfg-links

    Also see "Model Links" in the introduction docs: http://docs.sencha.com/extjs/5.1/5.1....app.ViewModel
    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.

  4. #4
    Sencha User
    Join Date
    Sep 2014
    Posts
    39
    Answers
    2
    Vote Rating
    7
      0  

    Default

    I have read through both of those a few times. I don't understand what the links and data configs are for and how to use them. Let me back up and explain what I am trying to accomplish. I have a model 'Quote' setup with a bunch of fields. one of the items in a quote is a store of 'LineItem' called LineItems. This store is created using a reference.


    In the application I have a store of abbreviated 'Quote'. Each one is a subset of data. When I click on one of these items, I get the ID and need to load a full quote from the server. Once I load the data, I need to display fields from the Quote, and bind the store of 'LineItem' to a dataview I have.


    I am not sure of the best way to do this. In researching the recommended way to accomplish this, I cam across the links config on the viewmodel for binding one instance of a model to a viewmodel.

  5. #5
    Sencha User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,099
    Answers
    734
    Vote Rating
    969
      1  

    Default

    The links config gives you a declarative way to create (and load) models, it is roughly equivalent to:

    Code:
    // a
    links: {
        theUser: {
            type: 'User',
            id: 1
        }
    }
    
    // b
    var rec = new User({id: 1});
    rec.load();
    viewModel.set('theUser', rec);
    Links also give you the benefit of of consulting the session to check if there's an existing record.
    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.

  6. #6
    Sencha User
    Join Date
    Sep 2014
    Posts
    39
    Answers
    2
    Vote Rating
    7
      3  

    Default

    Ok. That all makes sense. There are two things I was confused on with links.

    1) In your code below, you are hard coding an id to be loaded. Is this how it is meant to be used? I was able to set it programatically by not declaring it in the viewmodel itself, but calling:

    Code:
    var myId = selectedItem.id;
    this.getViewModel().setLinks({theQuote: {type: Myapp.model.quote, id: myId}});
    2) When the above code executes, the server automatically goes to get the record, which is cool. How can I handle this with a call back function?

    2a) I would like to know how to have the program 'wait' for the call to finish, but in my implementation I need it to. Once my data loades into the 'theQuote' variable in the links config it is in the format below. When I bind the Quote number for example, I use '{theQuote.QuoteNumber}'. How can I access the LineItems store to bind to my dataview?

    data structure:
    Code:
    Quote: {
    	LineItems,
    	data: {
    		QuoteNumber: '123'
    	}
    }
    Because the LineItems are at the same level as the 'theQuote' I can't figure out how to bind the store 'LineItems' to the dataview.

    I have since stopped using the links config and am now using the data config, which meets all of my needs. I call the load myself, which allows me to implement a callback function, and I can bind the 'LineItems' store to the dataview in my view.

    I am really surprised there isn't just a models config that works just like the stores config allowing users to bind to set up a model / proxy and bind to a single model.

  7. #7
    Sencha Premium Member
    Join Date
    Sep 2015
    Posts
    17
    Vote Rating
    2
      2  

    Default

    Quote Originally Posted by lsamples View Post
    Ok. That all makes sense. There are two things I was confused on with links.

    1) In your code below, you are hard coding an id to be loaded. Is this how it is meant to be used?
    I'm curious about this too. Every example is exactly the same with just a hard coded id value. How are you supposed to use and have it actually be useful?

  8. #8
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,351
    Answers
    13
    Vote Rating
    422
      1  

    Default

    Thanks. I'm using this now. Do you know why I need to prefix my model name with "App.model."? You seem to be getting by just fine without it in your example.

    Code:
        var popup = new App.view.ActivityInfoPopup({
            renderTo: Ext.getBody(),
            viewModel: {
                links: {
                    theActivity: {
                        type: 'App.model.ActivityInfo',
                        id: ActivityID
                    }
                }
            }
        });
    
    
        popup.show();

  9. #9
    Sencha Premium User
    Join Date
    Mar 2015
    Posts
    40
    Vote Rating
    0
      0  

    Default

    I have a corresponding to the topic question, is it possible to set a dynamic url using links as it is done for stores? i.e.
    Code:
    links: {
      foo: {
        type: 'MyApp.model.TestModel',
        proxy: {
          url: '/base_url/{id}'
        }
      }
    }

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

    Default

    I'm sure that's possible, but I can't test it right now. I can only say that I'm sure I've done this in some of my apps. If '{id}' doesn't exist then the model won't exist either, which will cause you no end of grief.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •