PDA

View Full Version : Store can't handle data where a number preceeds the number 0 in the id property



Nikkelmann
2 Aug 2011, 3:28 AM
Sencha Touch version tested:

1.1.0



only default sencha-touch.css

Platform tested against:

Safari 5.1 (Windows 7 32bit)
Android 2.2

Description:

Store can't handle data where a number preceeds the number 0 in the id property, eg. -1, 0, 1 or 2, 0, 1. The internalid of the record with id 0 is set to 'Ext-record-X' where X is a number. If the id starts from 0 there is no problem.
The problem is the same when loading data from AJAX.

Test Case:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Select fails on zero</title>
<link rel="stylesheet" href="http://dev.sencha.com/deploy/touch/resources/css/sencha-touch.css" type="text/css">
<script type="text/javascript" src="http://dev.sencha.com/deploy/touch/sencha-touch.js"></script>
<script type="text/javascript">
Ext.setup({
icon: 'http://dev.sencha.com/deploy/touch/examples/sortable/icon.png',
glossOnIcon: false,
tabletStartupScreen: 'http://dev.sencha.com/deploy/touch/examples/sortable/tablet_startup.png',
phoneStartupScreen: 'http://dev.sencha.com/deploy/touch/examples/sortable/phone_startup.png',
onReady: function () {
Ext.regModel('User', {
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'phone', type: 'string', mapping: 'phoneNumber' }
]
});

var data = {
users: [
{
id: -1,
name: 'Jamie Avins',
phoneNumber: '-11 1234'
},
{
id: 0,
name: 'Tommy Maintz',
phoneNumber: '000 1234'
},
{
id: 1,
name: 'Ed Spencer',
phoneNumber: '111 1234'
},
{
id: 2,
name: 'Abe Elias',
phoneNumber: '222 1234'
}
]
};

var store = new Ext.data.Store({
autoLoad: true,
model: 'User',
data: data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
});

var txt = new Ext.form.TextField({ value: 'Sencha version: ' + Ext.version });

var select = new Ext.form.Select({
itemId: 'id_form_sel',
name: 'sel',
label: 'Selskab',
valueField: 'id',
displayField: 'name',
scope: this,
store: store,
listeners: {
scope: this,
'change': function (select, value) {
txt.setValue('Selected value: ' + value);
}
}
});

new Ext.Application({
launch: function () {
new Ext.Panel({
fullscreen: true,
items: [select, txt]
});
}
});
}
});
</script>
</head>

<body>
</body>
</html> Steps to reproduce the problem:

Select the second item in the select cmp ("Tommy Maintz" id: 0).

The result that was expected:

Select cmp should select the item with id: 0
The value parameter of the change event should be 0

The result that occurs instead:

Select cmp selects the item with id: -1
The value parameter of the change event is -1 in Safari, 0 on Android 2.2

Debugging already done:

console.log(store) shows that store.data.keys[1] is "ext-record-1" instead of 0.

Possible fix:

This bug might stem from the same bug in this report: http://www.sencha.com/forum/showthread.php?138566-getById-fails-after-adding-record-to-store

Nikkelmann
15 Aug 2011, 3:47 AM
Bump

Nikkelmann
22 Aug 2011, 10:58 PM
Bump

Bump...