<!-- you could put this in a separate file too - and load it with Ext's Loader -->
<script id="todo-tpl" type="text/template">
<ul>
<tpl for=".">
<li class="todo <tpl if="isDone"> todo-done</tpl>">{description:htmlEncode}</li>
</tpl>
</ul>
</script>
// TODO: This would be in a seperate file
Ext.define('ToDoModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'description',
type: 'string'
}, {
name: 'isDone',
type: 'boolean'
}]
});
// TODO: this would be in a seperate file
var toDoStore = Ext.create('Ext.data.Store', {
id: 'ToDoStore',
model: 'ToDoModel',
data: [{
'description': 'Something',
'isDone': true
}, {
'description': 'Something else',
'isDone': false
}, {
'description': 'etc.',
'isDone': false
}]
});
var toDoTpl = new Ext.XTemplate(Ext.fly('todo-tpl').getHTML());
var listView = Ext.create('Ext.view.View', {
// REQUIRED
store: toDoStore,
// REQUIRED - Remembering in the past I had problems with itemTpl generating additional elements around each item
tpl: toDoTpl,
renderTo: Ext.getBody(),
// REQUIRED
itemSelector: '.todo',
baseCls: 'todo-list',
emptyText: 'No items :(',
// We need to do this because we are setting data on the store directly,
// normally emptyText will be applied if after store.load the store has no data.
deferEmptyText: false,
listeners: {
itemclick: function (view, record) {
this.markDone(record);
}
},
markDone: function (record) {
var isDone = record.get('isDone');
if (isDone === false) {
record.set('isDone', true);
}
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.