我剛開始使用Sencha framework 2.x.這是我的應用程序:Sencha 2.x MVC:通過id獲取元素
應用程序/ app.js
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
name: 'App',
controllers: ['Generators'],
models: [],
stores: [],
views: ['Main', 'Generator'],
launch: function() {
Ext.create('App.view.Main');
}
});
應用程序/視圖/ Main.js
Ext.define('App.view.Main', {
extend: 'Ext.NavigationView',
requires: [
'App.view.Generator'
],
config: {
fullscreen: true,
items: [
{
xtype: 'generatorview'
}
]
}
});
應用程序/視圖/ Generator.js
Ext.define('App.view.Generator', {
extend: 'Ext.Container',
xtype: 'generatorview',
id: 'generator',
config: {
layout: 'vbox',
items: [
{
xtype: 'panel',
html: 'My message: <a id="xxxSet">Set</a> :: <span id="xxxMsg">...</span>',
flex: 1
},
{
dock: 'bottom',
xtype: 'toolbar',
items: []
}
]
}
});
應用/controller/Generator.js
Ext.define('App.controller.Generators', {
extend: 'Ext.app.Controller',
config: {
refs: {}
},
init: function() {
this.control({
'#xxxSet': { // QUESTION1
tap: 'setMyMessage'
}
});
},
setMyMessage: function() {
'#xxxMsg'.html('Set this message'); // QUESTION2
}
});
正如你所看到的,我把問題放在最後一部分(控制器)中。
- 問題1:怎樣可以設置一個抽頭函數到視圖作爲HTML內容限定的元件(#xxxSet) 。
- 問題2:如何將 消息中的元素(#xxxMsg)在視圖中定義爲HTML 內容。
xxxSet =按鈕的ID
消息支架
THX的xxxMsg = ID!