Created
August 16, 2014 07:47
-
-
Save noroot/f094258eaa80e26a5ae3 to your computer and use it in GitHub Desktop.
ExtJS 5 ViewModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define('TestViewModel', { | |
extend: 'Ext.app.ViewModel', | |
alias: 'viewmodel.test', // connects to viewModel/type below | |
data: { | |
firstName: 'John', | |
lastName: 'Doe' | |
}, | |
formulas: { | |
// We'll explain formulas in more detail soon. | |
name: function (get) { | |
var fn = get('firstName'), ln = get('lastName'); | |
return (fn && ln) ? (fn + ' ' + ln) : (fn || ln || ''); | |
} | |
} | |
}); | |
Ext.define('TestView', { | |
extend: 'Ext.panel.Panel', | |
layout: 'form', | |
// Always use this form when defining a view class. This | |
// allows the creator of the component to pass data without | |
// erasing the ViewModel type that we want. | |
viewModel: { | |
type: 'test' // references alias "viewmodel.test" | |
}, | |
bind: { | |
title: 'Hello {name}' | |
}, | |
defaultType: 'textfield', | |
items: [{ | |
fieldLabel: 'First Name', | |
bind: '{firstName}' | |
},{ | |
fieldLabel: 'Last Name', | |
bind: '{lastName}' | |
},{ | |
xtype: 'button', | |
text: 'Submit', | |
bind: { | |
hidden: '{!name}' | |
} | |
}] | |
}); | |
Ext.onReady(function () { | |
Ext.create('TestView', { | |
renderTo: Ext.getBody(), | |
width: 400 | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment