5
試圖學習Sencha Touch 2,我似乎無法找到如何在選擇字段中設置默認選定選項。下面是我在Main.js觀點已經試過:設置Sencha Touch 2 selectfield的選定選項
Ext.define('mobile-form.view.Main', {
extend: 'Ext.Container',
requires: [
'Ext.TitleBar',
'Ext.form.FieldSet',
'Ext.field.Select',
],
config: {
fullscreen: true,
layout: 'vbox',
items: [
{
xtype: 'titlebar',
docked: 'top',
cls: 'titlebar'
},
{
xtype: 'panel',
scrollable: 'vertical',
cls: 'form_container',
flex: 1,
items: [
{
xtype: 'fieldset',
items: [
{
xtype: 'selectfield',
label: 'Desired Policy Type',
labelWidth: 'auto',
name: 'test',
options: [
{text: 'Test 1', value: '1'},
{text: 'Test 2', value: '2'},
// this doesn't work
{text: 'Test 3', value: '3', selected: true},
{text: 'Test 4', value: '4'}
],
listeners: {
// this doesn't work
painted: function() {
console.log(this);
this.select(3);
}
}
}
]
}
]
}
]
}
});
我需要,而不是等到應用程序本身是準備好了?事情是這樣的:
Ext.application({
name: 'mobile-form',
requires: [
'Ext.MessageBox'
],
views: ['Main'],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/[email protected]',
'144': 'resources/icons/[email protected]'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('mobile-form.view.Main'));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
},
onReady: function() {
{SomeWayToTargetElement}.select(2);
}
});
如果是的話我怎麼在我的意見設置元素的標識符,這樣我可以將它們應用的onReady事件中的目標?
任何幫助,非常感謝。愛的Sencha到目前爲止。他們的文檔非常棒。只需要找到更多這些文檔的例子,而且我們的墨跡會好得多。 :P
啊!不能相信我在文檔中錯過了...非常感謝。 –
是的,我一開始就在尋找類似defaultValue或selectedValue的東西,但後來我找到了它。 –