所以我正在玩拉力賽sdk來爲拉力賽建立自定義應用程序,而我正在嘗試做一些類似的事情。我正在使用拉力賽文本框和拉力賽對話框來實施它。它還沒有一個完美的功能,但我想要做的是保持我添加的對話框的狀態,以便在刷新應用程序時它們仍然存在。我還沒有弄明白這一點,而且我看不出它是通過閱讀關於維持國家的拉力指南來得到它的。如何使用rally sdk 2.1在自定義拉力賽應用程序中維護對話組件的狀態?
這裏是我到目前爲止的代碼:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
stateful: true,
componentCls: 'app',
getState: function() {
return {
dialogs: this.dialogs
};
},
applyState: function(state) {
this.dialogs = state.dialogs;
},
doLayout: function() {
var me = this;
var textField = Ext.create('Rally.ui.TextField', {
fieldLabel: 'Add task:',
listeners: {
scope: me,
specialkey: me._checkEnter
}
});
me.add(textField);
},
launch: function() {
this.doLayout();
this.taskCounter = 0;
this.yPosition = 50;
this.dialogs = [];
},
_checkEnter: function(field, event) {
if (event.getKey() == event.ENTER) {
this._onEnter(field);
}
},
_onEnter: function(field) {
this.taskCounter = this.taskCounter + 1;
var dialog = Ext.create(Rally.ui.dialog.Dialog, {
context: this.getContext(),
id: (99990 + this.taskCounter).toString(),
autoShow: true,
autoCenter: false,
draggable: false,
closable: true,
modal: false,
width: 300,
x: 100,
y: this.yPosition,
title: 'Task ' + this.taskCounter,
items: {
xtype: 'component',
html: field.getRawValue(),
padding: 10
}
})
this.yPosition = this.yPosition + 100;
}
});
**** ****編輯
所以我一直在努力使這項工作。我一直試圖在頁面刷新和導航之間保持狀態,並開始通過使用數組來存儲不同的字符串來測試它,並且在返回到應用程序時查看它們是否仍然存在。每次我在字段框中輸入內容,然後按回車鍵,就會創建一個對話框,並調用saveState(),並嘗試保存一個字符串,其中包含創建的對話框的ID。但是,似乎getState函數僅保存第一次調用時的狀態(在第一次輸入時),因爲當我刷新或返回到應用程序時,唯一保留的字符串是第一個創建的對話框的ID ,但不是以下的。這是來自SDK的saveState函數的錯誤,還是我使用它錯了?謝謝。這是代碼:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
stateful: true,
componentCls: 'app',
getState: function() {
console.log('getting state');
if(this.dialogs.length > 0) {
console.log('this.dialogs from getState:', this.dialogs);
var newState = {
currentDialogs: this.dialogs
};
console.log(newState);
return newState;
}
return null;
},
applyState: function(state) {
console.log('applying state');
console.log('current state:', state);
if(state.currentDialogs) {
this.dialogs = state.currentDialogs;
console.log('this.dialogs after applying state:', this.dialogs);
}
else {
this.dialogs = [];
}
},
doLayout: function() {
var me = this;
var textField = Ext.create('Rally.ui.TextField', {
fieldLabel: 'Add task:',
listeners: {
scope: me,
specialkey: me._checkEnter
}
});
me.add(textField);
},
launch: function() {
this.dialogs = this.dialogs;
this.doLayout();
this.taskCounter = 0;
this.yPosition = 50;
},
_checkEnter: function(field, event) {
if (event.getKey() === event.ENTER) {
this._onEnter(field);
}
},
_onEnter: function(field) {
this.taskCounter = this.taskCounter + 1;
var dialog = Ext.create(Rally.ui.dialog.Dialog, {
context: this.getContext(),
autoShow: true,
autoCenter: false,
draggable: false,
closable: true,
modal: false,
width: 300,
x: 100,
y: this.yPosition,
title: 'Task ' + this.taskCounter,
items: {
xtype: 'component',
html: field.getRawValue(),
padding: 10
}
});
this.yPosition = this.yPosition + 100;
this.dialogs.push((99990 + this.taskCounter).toString());
this.saveState();
}
});
謝謝凱爾,幫了很大忙。我也認爲它可能是這樣的,不知道爲什麼concat解決方案沒有想到。無論如何,還有一件事,是否有辦法讓這個持久數據可以在集會訂閱中的所有用戶上使用,而無需使用外部數據庫作爲存儲模型? –