Sencha Touch 1.1.1 でExt.DataViewを使っていて発生したエラー。

Uncaught TypeError: Cannot read property 'parentNode' of undefined
sencha-touch-debug-w-comments.js:21350


原因は、tplに設定した Ext.XTemplate の中に itemSelector で指定したセレクタに当てはまる要素がなかったことでした。

this.list = new Ext.DataView({
emptyText: 'データがありません',
itemSelector:'div.my_wrap',
store: Ext.StoreMgr.get('MyStore'),
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div class="my_unit">',
'<p>{text}</p>',
'</div>',
'</tpl>'
),
});


以下のように、するとOKでした。はじめ、何を勘違いしたのかitemSelectorで指定した要素が自動的に追加されてmy_unitはその配下に納まるのかと思っていて気づきませんでした・・・。itemSelectorで指定した要素がtpl内に存在すればOKです。どの要素を基準にしてテンプレートを展開するかをここで指定しているようです。

this.list = new Ext.DataView({
emptyText: 'データがありません',
itemSelector:'.my_unit',
store: Ext.StoreMgr.get('MyStore'),
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div class="my_unit">',
'<p>{text}</p>',
'</div>',
'</tpl>'
),
});


初歩的なミスでしたが、エラー文で検索しても答えが出てこなかったので、備忘録として。