Xin chào, tôi cần xác định biến toàn cục để sử dụng ở bất kỳ đâu trong ứng dụng của tôi. Tôi tuyên bố biến toàn cục baseUrl trong app.js của tôi. Xin vui lòng xem bên dưới app.jsBiến toàn cục sencha touch 2.1
//<debug>
Ext.Loader.setPath({
'Ext': 'touch/src',//Location of the sencha touch source files
'bluebutton': 'app',
});
//</debug>
Ext.application({
name: 'bluebutton',//Application Path, all classes in you app. For eg blueButton.view.Main.case sensitive
views: ['Main',
'BlueButton.CouponMain',
'BlueButton.CouponList',
'BlueButton.CouponList2',
'BlueButton.CouponList3',
'BlueButton.TransactionMain',
],
stores : [
'BlueButton.GlobalVariable',
],
models : ['BlueButton.GlobalVariable',
'BlueButton.MemberDetail',
],
controllers: ['Main',
'BlueButton.MemberList',
],
requires: [
'Ext.MessageBox',
],
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'
},
//--Global value--
baseUrl: 'http://192.168.251.108:8080',
//--Global value--
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
var LoginLS = Ext.getStore('LoginLS');
LoginLS.load();
var record = LoginLS.getAt(0);
if(record != undefined){
var sessionId = record.get('sessionId');
if (sessionId !=undefined){
var mainView = Ext.getCmp("mainview");
if(!mainView){
mainView = Ext.create('bluebutton.view.Main');
}
Ext.Viewport.setActiveItem(mainView);
}
else
{
var loginView = Ext.getCmp("loginview");
if(!loginView){
loginView = Ext.create('bluebutton.view.Login');
}
Ext.Viewport.setActiveItem(loginView);
}
}
else{
var loginView = Ext.getCmp("loginview");
if(!loginView){
loginView = Ext.create('bluebutton.view.Login');
}
Ext.Viewport.setActiveItem(loginView);
// //--Disable this line --
// var mainView = Ext.getCmp("mainview");
// if(!mainView){
// mainView = Ext.create('bluebutton.view.Main');
// }
// Ext.Viewport.setActiveItem(mainView);
// //--Disable this line --
}
// Ext.create('bluebutton.view.TopMenuList');
},
init: function() {
this.callParent(arguments);
},
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();
}
}
);
}
});
model.js
Ext.define('bluebutton.model.BlueButton.CouponList', {
extend: 'Ext.data.Model',
config: {
idProperty: 'couponId',
fields: [
{ name: 'couponId' },
{ name: 'couponName' },
{ name: 'description' },
{ name: 'amount' },
{ name: 'couponType' },
{ name: 'merchant_bbID' },
{ name: 'sessionId' },
{ name: 'deviceId' },
],
proxy: {
type: 'rest',
url: bluebutton.app.baseUrl +'/WebCommon/rest/BBWebService/getCouponList',
actionMethods: {
create: 'POST',
read: 'GET',
update: 'PUT',
destroy: 'DELETE'
},
noCache: false, // get rid of the '_dc' url parameter
extraParams: {
sessionId: "1",
merchant_bbID: "merchant1",
},
// timeout:1000,
// listeners: {
// exception: function(proxy, response, operation) {
// alert("Connection Problem");
// Ext.Viewport.setMasked(false); // hide the load screen
//
// }
// },
reader: {
type: 'json',
rootProperty: 'couponList'
},
writer: {
type: 'json',
},
}
}
});
Sau đó, tôi sử dụng basedUrl trong model.js tôi. Nó có thể hoạt động khi tôi sử dụng trình duyệt để xem. Nhưng khi tôi sử dụng sencha ứng dụng xây dựng thử nghiệm để biên dịch ứng dụng của tôi,
tôi đã sử dụng trình duyệt để mở và nó chỉ cho tôi một lỗi chưa gặp thông báo lỗi : Không thể đọc thuộc 'baseUrl' không xác định. Bất kỳ ý tưởng?
Câu trả lời dưới đây có giúp được không? – Gendaful