Possible bug in Ext.View - Ext JS

本文解决了使用ExtJS框架中View组件无法正确刷新的问题。通过调整store读取JSON记录的方法和修正模板应用数据的方式,成功实现了视图的更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I used the following code to create a View that I could update with JSON data.

var Root = Ext.data.Record.create([
		{name: 'refId', mapping: 'refId'},
		{name: 'displayType', mapping: 'displayType'},
		{name: 'systemName', mapping: 'systemName'},
		{name: 'title', mapping: 'title'},
		{name: 'parentKeyName', mapping: 'parentKeyName'},
		{name: 'urlArgs', mapping: 'urlArgs'},
		{name: 'cls', mapping: 'cls'}
]);
var sectionReader = new Ext.data.JsonReader({
	root: 'root',
	id: 'refId'
}, Root); 
var sectionDS = new Ext.data.Store({
	proxy: new Ext.data.MemoryProxy(),
	reader: sectionReader
});
var tplSection = new Ext.Template( '<div class="{cls}" id="{refId}" name="{systemName}" type="{displayType}" display="{title}" title=">>Load {title} Menu" key="{parentKeyName}" args="{urlArgs}">{title}</div>' );
tplSection.compile();
// initialize the Section View
var sectionView = new Ext.View('myview', tplSection, 
  { 
	store: sectionDS, 
	singleSelect: true, 
	selectedClass: 'list-row-selected', 
	emptyText: 'Unable to load menu roots' 
  });
I was trying to update a Ext.View by manually reading JSON records into the view's store and refreshing the view using the following code.

var records = sectionView.store.reader.readRecords({'root': someJSONData});
sectionView.store.loadRecords(records, {add: true}, true);
sectionView.refresh();
The code would execute but the view was never refreshed. After digging into the debug code, I found that the following existed at line 9079:

    refresh : function(){
        var t = this.tpl;
        this.clearSelections();
        this.el.update("");
        var html = [];
        var records = this.store.getRange();
        if(records.length < 1){
            this.el.update(this.emptyText);
            return;
        }
        for(var i = 0, len = records.length; i < len; i++){
            var data = this.prepareData(records[i].data, i, r);
            html[html.length] = tpl.apply(data);
        }
        this.el.update(html.join(""));
        this.nodes = this.el.dom.childNodes;
        this.updateIndexes(0);
    },
this.prepareData uses an argument r that doesn't appear to exist.

tpl.apply(data) should either be this.tpl.apply(data) or t.apply(data)

After making those changes, the view refreshed as expected.
Reply With Quote
  #2  
Old 02-19-2007, 10:42 PM
Default

Thank you. I have made those changes.

Btw, the store API does have some functions other than loadRecords (add, insert) that may be more appropriate. loadRecords may be a private function for the release.
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值