PDA

View Full Version : Help with Nested List



dailak
22 Dec 2010, 3:46 PM
Hi,

I am a new Sencha developer. I tried to take the Nested List example to put it on my local website. I copied the carregions.json to the root of the website and created a index.html as following, but it's still not showing up. Please help.

<!DOCTYPE html>
<html>
<head>
<title>Nested List</title>
<script src="lib/touch/sencha-touch-debug.js" type="text/javascript"></script>
<link href="lib/touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
new Ext.Application({
name: 'Nested List',
launch: function() {

Ext.regModel('Cars', {
fields: [
{name: 'text', type: 'string'}
]
});


var txtFld = new Ext.form.Text({
label: 'Name'
});

var calculateDesiredWidth = function() {
var viewWidth = Ext.Element.getViewportWidth(),
desiredWidth = Math.min(viewWidth, 400) - 10;

return desiredWidth;
};


var editPnl = new Ext.Panel({
floating: true,
centered: true,
modal: true,
width: calculateDesiredWidth(),

dockedItems: [{
dock: 'top',
xtype: 'toolbar',
title: 'Editing Item'
},{
dock: 'bottom',
xtype: 'toolbar',
items: [{
text: 'Cancel',
handler: function() {
editPnl.hide();
}
},{
xtype: 'spacer'
},{
text: 'Change',
ui: 'action',
handler: function() {
var activeList = demos.NestedList.getActiveItem(),
record = activeList.getSelectedRecords()[0];
record.set('text', txtFld.getValue());

// Workaround: selection *should* be maintained.
activeList.getSelectionModel().select(record);

editPnl.hide();
}
}]
}],
items: [{
xtype: 'form',
items: [{
xtype: 'fieldset',
items: [txtFld]
}]
}]
});

Ext.EventManager.onOrientationChange(function() {
editPnl.setWidth(calculateDesiredWidth());
});

var editBtn = new Ext.Button({
text: 'Edit',
disabled: true,
handler: function() {
editPnl.show();

var activeList = demos.NestedList.getActiveItem(),
record = activeList.getSelectedRecords()[0];

txtFld.setValue(record.get('text'));
}
});


var store = new Ext.data.TreeStore({
model: 'Cars',
proxy: {
type: 'ajax',
url: 'carregions.json',
reader: {
type: 'tree',
root: 'items'
}
}
});

demos.NestedList = new Ext.NestedList({
plugins: [new Ext.LeafSelectedPlugin()],
toolbar: {
items: [{xtype: 'spacer'}, editBtn]
},
store: store
});

// leafselected event is provided by the LeafSelectedPlugin.js
demos.NestedList.on('leafselected', function(enabled) {
editBtn.setDisabled(!enabled);
});



}
});
</script>
</head>
</html>

mikegriffin
28 Jun 2011, 4:42 AM
You need the LeafSelectedPlugin.js from the kitchen sink and the json file on your server.

I got this working by amending your code to

<!DOCTYPE html>
<html>
<head>
<title>Nested List</title>
<script src="../sencha-touch-debug.js" type="text/javascript"></script>
<script src="app/LeafSelectedPlugin.js" type="text/javascript"></script>
<link href="../resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

var App = new Ext.Application({
name: 'NestedListApp',
launch: function() {

Ext.regModel('Cars', {
fields: [
{name: 'text', type: 'string'}
]
});


var txtFld = new Ext.form.Text({
label: 'Name'
});

var calculateDesiredWidth = function() {
var viewWidth = Ext.Element.getViewportWidth(),
desiredWidth = Math.min(viewWidth, 400) - 10;

return desiredWidth;
};


var editPnl = new Ext.Panel({
floating: true,
centered: true,
modal: true,
width: calculateDesiredWidth(),

dockedItems: [{
dock: 'top',
xtype: 'toolbar',
title: 'Editing Item'
},{
dock: 'bottom',
xtype: 'toolbar',
items: [{
text: 'Cancel',
handler: function() {
editPnl.hide();
}
},{
xtype: 'spacer'
},{
text: 'Change',
ui: 'action',
handler: function() {
var activeList = NestedList.getActiveItem(),
record = activeList.getSelectedRecords()[0];
record.set('text', txtFld.getValue());

// Workaround: selection *should* be maintained.
activeList.getSelectionModel().select(record);

editPnl.hide();
}
}]
}],
items: [{
xtype: 'form',
items: [{
xtype: 'fieldset',
items: [txtFld]
}]
}]
});

Ext.EventManager.onOrientationChange(function() {
editPnl.setWidth(calculateDesiredWidth());
});

var editBtn = new Ext.Button({
text: 'Edit',
disabled: true,
handler: function() {
editPnl.show();

var activeList = NestedList.getActiveItem(),
record = activeList.getSelectedRecords()[0];

txtFld.setValue(record.get('text'));
}
});


var store = new Ext.data.TreeStore({
model: 'Cars',
proxy: {
type: 'ajax',
url: 'json.txt',
reader: {
type: 'tree',
root: 'items'
}
}
});

var NestedList = new Ext.NestedList({
plugins: [new Ext.LeafSelectedPlugin()],
toolbar: {
items: [{xtype: 'spacer'}, editBtn]
},
store: store
});

// leafselected event is provided by the LeafSelectedPlugin.js
NestedList.on('leafselected', function(enabled) {
editBtn.setDisabled(!enabled);
});

viewport = new Ext.Panel({
fullscreen: true,
layout: 'card',
cardAnimation: 'slide',
items: [
NestedList
]
});

}
});
</script>
</head>
</html>