gizmoone
16 Jul 2012, 6:54 AM
hello,
i try to load data from file (online) into localstorage (offline).
View from localstorage .
When i try from data file is ok but from localstorage don't work.
i don't no why!
proto.app.js
Ext.application({
name: 'proto',
requires: [
'Ext.MessageBox'
],
views: ['Fonction'],
models: [
'Fonction'
],
stores: [
'OnLineFonctions',
'OffLineFonctions'
],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon@2x.png',
'144': 'resources/icons/Icon~ipad@2x.png'
},
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('proto.view.Fonction'));
// Ext.create('proto.view.Fonction', {fullscreen: true});
},
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();
}
}
);
}
});
proto/data/liste.json
{"post":[ { Id: "1", Name:"id1", Description: "a", Visible: "O", CreatedAt: "", UpdatedAt: "", DeletedAt: "" },
{ Id: "2", Name: "id4", Description: "a", Visible: "N", CreatedAt: "", UpdatedAt: "", DeletedAt: "" },
{ Id: "3", Name: "id3", Description: "a", Visible: "N", CreatedAt: "", UpdatedAt: "", DeletedAt: "" },
{ Id: "4", Name: "id4", Description: "a", Visible: "O", CreatedAt: "", UpdatedAt: "", DeletedAt: "" }]}
proto/app/model/Fonction.js
Ext.define('proto.model.Fonction', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' },
{ name: 'Description', type: 'string' },
{ name: 'Visible', type: 'boolean' },
{ name: 'CreatedAt', type: 'date' },
{ name: 'UpdatedAt', type: 'date' },
{ name: 'DeletedAt', type: 'date' }
]
}
});
proto/app/store/OnLineFonctions.js
Ext.define('proto.store.OnLineFonctions', {
extend: 'Ext.data.Store',
requires: [
'proto.model.Fonction'
],
config: {
model: 'proto.model.Fonction',
storeId: 'OnLineFonctions',
// proxy fichier
proxy: {
type: 'ajax',
url: 'data/liste.json',
reader: {
type: 'json',
rootProperty: 'post'
}
},
autoLoad: true,
listeners: {
load: function() {
// Clear proxy from offline store
OffLineFonctions.proxy.clear();
// Loop through records and fill the offline store
this.each(function(record) {
OffLineFonctions.add(record.data);
});
// Sync the offline store
OffLineFonctions.sync();
// Remove data from online store
OnLineFonctions.removeAll();
}
}
}
});
proto/app/OffLineFonctions.js
Ext.define('proto.store.OffLineFonctions', {
extend: 'Ext.data.Store',
requires: [
'proto.model.Fonction'
],
config: {
model: 'proto.model.Fonction',
proxy: {
type: 'localstorage',
id: 'myFonctions'
}
}
});
proto/app/view/Fonction.js
Ext.define('proto.view.Fonction', {
extend: 'Ext.dataview.List',
config: {
store: 'OffLineFonctions',
onItemDisclosure: true,
itemTpl: [
'<div> {Name} {Id} {Visible}</div>'
]
}
});
thanks for you help
i try to load data from file (online) into localstorage (offline).
View from localstorage .
When i try from data file is ok but from localstorage don't work.
i don't no why!
proto.app.js
Ext.application({
name: 'proto',
requires: [
'Ext.MessageBox'
],
views: ['Fonction'],
models: [
'Fonction'
],
stores: [
'OnLineFonctions',
'OffLineFonctions'
],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon@2x.png',
'144': 'resources/icons/Icon~ipad@2x.png'
},
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('proto.view.Fonction'));
// Ext.create('proto.view.Fonction', {fullscreen: true});
},
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();
}
}
);
}
});
proto/data/liste.json
{"post":[ { Id: "1", Name:"id1", Description: "a", Visible: "O", CreatedAt: "", UpdatedAt: "", DeletedAt: "" },
{ Id: "2", Name: "id4", Description: "a", Visible: "N", CreatedAt: "", UpdatedAt: "", DeletedAt: "" },
{ Id: "3", Name: "id3", Description: "a", Visible: "N", CreatedAt: "", UpdatedAt: "", DeletedAt: "" },
{ Id: "4", Name: "id4", Description: "a", Visible: "O", CreatedAt: "", UpdatedAt: "", DeletedAt: "" }]}
proto/app/model/Fonction.js
Ext.define('proto.model.Fonction', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' },
{ name: 'Description', type: 'string' },
{ name: 'Visible', type: 'boolean' },
{ name: 'CreatedAt', type: 'date' },
{ name: 'UpdatedAt', type: 'date' },
{ name: 'DeletedAt', type: 'date' }
]
}
});
proto/app/store/OnLineFonctions.js
Ext.define('proto.store.OnLineFonctions', {
extend: 'Ext.data.Store',
requires: [
'proto.model.Fonction'
],
config: {
model: 'proto.model.Fonction',
storeId: 'OnLineFonctions',
// proxy fichier
proxy: {
type: 'ajax',
url: 'data/liste.json',
reader: {
type: 'json',
rootProperty: 'post'
}
},
autoLoad: true,
listeners: {
load: function() {
// Clear proxy from offline store
OffLineFonctions.proxy.clear();
// Loop through records and fill the offline store
this.each(function(record) {
OffLineFonctions.add(record.data);
});
// Sync the offline store
OffLineFonctions.sync();
// Remove data from online store
OnLineFonctions.removeAll();
}
}
}
});
proto/app/OffLineFonctions.js
Ext.define('proto.store.OffLineFonctions', {
extend: 'Ext.data.Store',
requires: [
'proto.model.Fonction'
],
config: {
model: 'proto.model.Fonction',
proxy: {
type: 'localstorage',
id: 'myFonctions'
}
}
});
proto/app/view/Fonction.js
Ext.define('proto.view.Fonction', {
extend: 'Ext.dataview.List',
config: {
store: 'OffLineFonctions',
onItemDisclosure: true,
itemTpl: [
'<div> {Name} {Id} {Visible}</div>'
]
}
});
thanks for you help