Are there any tutorials on how to fill a treestore from Javascript?
What I want to do is load data from a WebSQL database and add it to the store to display it in a nested list. I've tried to use the store.add() and store.addData() functions, however with litte success.
It works if I try to load it from a local json file.
My store:
My Model:
My nested list view:
One try with addData:
What I want to do is load data from a WebSQL database and add it to the store to display it in a nested list. I've tried to use the store.add() and store.addData() functions, however with litte success.
It works if I try to load it from a local json file.
My store:
Code:
Ext.define('Muzic.store.Artists', {
extend: 'Ext.data.TreeStore',
config: {
storeId: 'Artists',
model: 'Muzic.model.Song',
//WORKING, from http://ift.tt/1oZqJti:
/*proxy: {
type: 'ajax',
url: '/data/catalogue.json',
reader: {
type: 'json',
root: 'items'
}
}*/
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
}
});
My Model:
Code:
Ext.define('Muzic.model.Song', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'title', type: 'string'},
{name: 'artist', type: 'string'},
{name: 'filepath', type: 'string'},
{name: 'alreadyHeard', type: 'boolean', defaultValue: false}
],
validations: [{ type: 'presence', field: 'filepath'}]
}
});
My nested list view:
Code:
Ext.define('Muzic.view.albums.Card', {
extend: 'Ext.NestedList',
xtype: 'nestedlist',
config: {
iconCls: 'album',
title: 'Artists',
store: 'Artists',
displayField: 'title'
}
});
One try with addData:
Code:
testAddData : function () {
var arr = [];
var obj = {items : [{
title:'artist',
filepath:'nothing',
items:[{
title: 'song',
filepath:'somewhere',
artist:'artist',
leaf:'true'
}],
leaf:'false'
}]};
arr.push(obj);
//console.log(JSON.stringify(obj));
Ext.getStore('Artists').addData(arr);
Ext.getStore('Artists').sync();
},
Aucun commentaire:
Enregistrer un commentaire