Results 1 to 4 of 4

Thread: Write to the parent ViewModel

  1. #1
    Sencha User
    Join Date
    May 2015
    Posts
    3

    Default Write to the parent ViewModel

    Acording to the ViewModel Internals Guide if I have few nested containers with their own viewmodels any changes in deeply nested textfield won't be reflected in the root viewmodel via binding. But I get the opposite behavior. Simple code like this one makes the parent and nested viewmodels to stay in sync:
    Code:
    Ext.define('TestView', {
        extend: 'Ext.panel.Panel',
        layout: 'form',
        viewModel: {
            data: {
                foo: 42
            }
        },
        bind: 'Foo is {foo}',
        
        items: {
            xtype: 'panel',
            layout: 'fit',
            viewModel: {
                data: {
                }
            },
            items: {
                xtype: 'textfield',
                bind: '{foo}'
            }
        }
    });
    
    
    Ext.onReady(function () {
        Ext.create('TestView', {
            renderTo: Ext.getBody(),
            width: 250
        });
    });
    What do I miss?

  2. #2
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664
    Answers
    512

    Default

    Nothing. You need a little trick. See http://extjs.eu/ext-examples/#vm-hierarchy
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


  3. #3
    Sencha User
    Join Date
    May 2015
    Posts
    3

    Default

    Quote Originally Posted by jsakalos View Post
    Nothing. You need a little trick. See http://extjs.eu/ext-examples/#vm-hierarchy
    Thanks for your reply! The thing is that I want to find out if the mentioned doc isn't outdated or "buggy": even without tricks I can modify parent viewmodel, but I think I shouldn't be able to do this according to it.

  4. #4
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664
    Answers
    512

    Default

    foo must be object for prototype chain to work.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


Similar Threads

  1. Replies: 3
    Last Post: 20 Nov 2015, 9:08 AM
  2. Replies: 4
    Last Post: 28 Apr 2015, 10:20 AM
  3. Replies: 3
    Last Post: 28 Apr 2015, 10:18 AM
  4. Forcing parent ViewModel data to be available to child
    By estesbubba in forum Ext 5: Q&A
    Replies: 1
    Last Post: 14 Aug 2014, 4:25 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
  •