我正在研究Sencha Touch應用程序,我正在學習它,因爲我喜歡JavaScript。Sencha Touch全局變量
這是我app.js
var App = new Ext.Application({
name: 'My First App',
//BaseURL: 'http://mydomain.com/testing/first/services/',
launch: function() {
this.views.viewport = new this.views.Viewport();
// this.BaseURL = "http://mydomain.com/testing/first/services/";
}
});
這是我的商店之一。
var newsStore = new Ext.data.Store({
model: 'News',
sorters: [{
property: 'PostedOn',
direction: 'DESC'
}],
proxy: {
type: 'ajax',
url: 'http://mydomain.com/testing/first/services/News.php',
reader: {
type: 'xml',
root: 'News',
record: 'New'
}
},
getGroupString: function(record) {
if (record && record.data.PostedOn) {
return record.get('PostedOn').toDateString();
}
else {
return '';
}
},
autoLoad: true
});
現在的問題是,如果我可以在整個應用程序中創建一個全局變量?它的名稱爲BaseURL我可以在所有數據存儲中使用它,當需要更改時,我只需更改它以反映整個應用程序。
我需要知道兩件事。
- 如何聲明全局應用程序級別的變量。
- 如何在視圖和商店中訪問該變量。
應用實例裏面?我想在App實例內部進行操作並通過App實例訪問它。 – Neutralizer
檢查我編輯的答案 – Luis
另請參閱Ext.namespace()和Ext.Application文檔。 「name」屬性應該不包含空格,並且可以用作全局標識符。 – romaninsh