Question

I need to change Toolbar title in sencha touch 2 from json that comes from http://example.com/new.json. Maybe I should use AJAX call to get json and then parse it... but how to insert value to title:'' Is there any possibility?

Main.js

Ext.define('Sencha.view.Main', {
extend: 'Ext.Container',
xtype: 'main',
requires: [
    'Ext.Toolbar',
    'Ext.Button',
    'Ext.Img',
    'Ext.Label',
    'Ext.form.FieldSet'
],

config: {
    layout: 'hbox',
    items: [
        {
            xtype: 'toolbar',
            docked: 'top',
            itemId: 'navBar',
            title: 'app', // need to change 'app' from json dynamically
            items: [ ..... ]
        }
     ]
   }
});

JSON example

{
  data: {
    add: {
      application_config: {
        datasources: [
          {
            data: {
              application_title: "test2" // 'test2' should be passed as value to title
            }
          }
        ]
      }
    }
  }
}
Was it helpful?

Solution

So you're looking for Toolbar setTitle()?

Perhaps you're asking how to access the nested toolbar in order to set its title.

var newTitle = ''; // parse your JSON response here

var mainView = Ext.Viewport.down('main'); // 'main' is the xtype of your view
var toolbar = main.down('#navBar'); // '#navBar' is the component query to grab the component with an itemId of "navBar"
toolbar.setTitle(newTitle);

You can clean up the code above as you like, but I was intentionally verbose to explain the steps to accomplish this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top