0
嗨,大家需要您的幫助來加載本地存儲。將現有本地存儲數據加載到商店並將其綁定到sencha中的選定字段
我想從我的本地存儲自動加載現有記錄。
然後綁定它來存儲和選擇字段。
我想加載現有記錄,以便當我在本地存儲中添加新記錄時,它不會重寫現有的ID編輯記錄。
下面是我的一些代碼
app.js
Ext.application({
name: 'IO',
requires: [
'Ext.MessageBox'
],
views: [
'Main'
],
stores: [
'Files'
],
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('IO.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();
}
}
);
}
});
Files.js - 商店
Ext.define('IO.store.Files', {
extend: 'Ext.data.Store',
alias: 'store.Files',
requires: [
'IO.model.File'
],
config: {
model: 'IO.model.File',
storeId: 'filestore',
proxy: {
type: 'localstorage',
id: 'filestoreproxy'
},
autoLoad: true
}
});
File.js - 型號
Ext.define('IO.model.File',{
extend: 'Ext.data.Model',
alias: 'model.File',
config: {
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
}
]
}
});
NumberListIO - 查看
Ext.define('IO.view.NumberListIO', {
extend: 'Ext.field.Select',
xtype: 'numberiolist',
id: 'IOSelectField',
cls: 'IOListSelectOption',
config:{
xtype: 'selectfield',
name: 'test',
options: [
{
text: "--- Select List ---",
value: ""
}
],
store: 'filestore',
displayField: 'name',
valueField: 'id'
}
});
我看不出你的問題。用您需要的邏輯擴展您的控制器並將商店附加到視圖。 –
那麼目前我沒有控制器,但我的問題是,當我添加項目到商店它成功保存在本地存儲和一個選項被添加到我的選擇字段,但是當我重新加載我的瀏覽器時,選擇字段再次爲空儘管在我的瀏覽器本地存儲中,我之前添加的數據在那裏。然後,當我嘗試再次添加項目時,現有數據將被新項目覆蓋。 –