Results 1 to 6 of 6

Thread: Detecting record change using a link:{} view model w/o a store

  1. #1
    Sencha User
    Join Date
    Jun 2008
    Posts
    242
    Answers
    22

    Default Detecting record change using a link:{} view model w/o a store

    Assuming I'm using a panel with a view model for editing a record, such as the following:

    Code:
    Ext.define('App.view.invoice.PanelModel', {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.invoice.panel',
    
    
        links: {
            invoice: {
                type: 'Invoice',
                id: 10
    
            }
        }
    });
    What is the easiest way to detect when changes have been made to the record? Record does not expose datachanged or similar events. Do I have to also make a private store and have this record be the only item it contains so I can watch the store for changes?

  2. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Quote Originally Posted by The0s View Post
    Assuming I'm using a panel with a view model for editing a record, such as the following:

    Code:
    Ext.define('App.view.invoice.PanelModel', {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.invoice.panel',
    
    
        links: {
            invoice: {
                type: 'Invoice',
                id: 10
    
            }
        }
    });
    What is the easiest way to detect when changes have been made to the record? Record does not expose datachanged or similar events. Do I have to also make a private store and have this record be the only item it contains so I can watch the store for changes?
    You could create a binding to your "invoice" link, and provide a callback. This will let you do whatever you need to do when the binding is updated.

    Code:
    var binding = {
       bindTo: '{invoice}',
       deep: true
    };
    myViewModel.bind(binding, callback( mymodel ) {
        // do whatever here
    });
    I hope that helps!

    Thanks!
    Joel

  3. #3
    Sencha User
    Join Date
    Jun 2008
    Posts
    242
    Answers
    22

    Default

    Joel, will this only detect changes made to the records properties if made through the view model itself such as viewModel.set('invoice.field','value')?

    For example, if I find the record and do: record.set('field','value'), will that bind?

  4. #4
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Quote Originally Posted by The0s View Post
    Joel, will this only detect changes made to the records properties if made through the view model itself such as viewModel.set('invoice.field','value')?

    For example, if I find the record and do: record.set('field','value'), will that bind?
    It should work that way as well, for example:

    Code:
    myViewModel.get('someboundmodel').set('name', 'New Name')
    I've included an example below. The "Update Model" button basically does what the example above does.

    Thanks
    Joel


  5. #5
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,372
    Answers
    20

    Default

    Is this fiddle code correct? Should config be an array?
    Code:
        constructor: function(config) {
            this.mixins.observable.constructor.call(this, config);
            // this.callParent(config); 
            this.callParent([config]); // <-- Use this instead?
        },

  6. #6
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    33

    Default

    LesJ, you are right. I'm using

    Code:
    constructor: function(config) {
        this.mixins.observable.constructor.call(this, config);
    this.callParent(arguments);
    }
    The other version results in a model without fields.

Posting Permissions

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