我的代码中有一个网格面板:
Ext.create('Ext.grid.Panel',{ id : 'frPanel-' + interfaceId,store : frStore,columns : [ { text : 'Sequence',dataIndex : 'ruleId',menudisabled : true },{ text : 'Source',dataIndex : 'source',renderer : function(value,MetaData) { var newValue = convertObjValue(value); if (newValue.match(/[-]+/i)) { MetaData.tdAttr = 'data-qtip="' + networkStore(value) + '"'; } return newValue; } },// paging bar at the bottom dockedItems : [ { xtype : 'pagingtoolbar',// same store GridPanel is using dock : 'bottom',displayInfo : true } ],height : 300,width : '100%',forceFit : true,renderTo : 'frContainer-' + interfaceId });
这些是我的辅助功能:
// To get the value after 2nd colon for object and object-group function convertObjValue(value) { var result; var exp = /.*?:.*?:(.*)/i; var newValue = value; if ((result = exp.exec(value)) != null) { if (result.index === exp.lastIndex) { exp.lastIndex++; } newValue = result[1]; } return newValue; }
商店:
function networkStore(value) { //var store = Ext.create('Ext.data.Store',{ var store = new Ext.data.Store({ model : 'networkModel',autoLoad : { timeout : 60000 },proxy : { type : 'ajax',url : networkObjsURL + "&" + Ext.urlEncode({ 'peId' : value }),reader : { type : 'json',idProperty : 'objValue' },} }); var hoverOutput = ""; if(store.data.length > 0){ store.data.items.forEach(function(item) { hoverOutput += item.data.objectValue + "</br>"; }); } console.log(hoverOutput); return hoverOutput;
最后但并非最不重要的是模型:
Ext.define('networkModel',{ extend : 'Ext.data.Model',fields : [ { name : 'objectValue' } ] });
现在问题来了.问题是当我不在商店的浏览器中放置断点时,值不会显示在qtip中.我猜这是因为网格面板在ajax响应之后没有等待来自商店的响应.有人可以帮我解决这种情况的解决方法吗?
提前致谢
解决方法
你试过设置吗?
autoLoad:false
然后像:
store.load({ callback: function(records,operation,success) { if (success == true) { //do your stuff var hoverOutput = ""; if(store.data.length > 0){ store.data.items.forEach(function(item) { hoverOutput += item.data.objectValue + "</br>"; }); } console.log(hoverOutput); return hoverOutput; } else { // the store didn't load,deal with it } } // scope: this,});
由于你的断点允许你看到你的数据,我认为你是正确的,因为它是一个延迟问题.由于Ext是异步的,因此在继续处理之前,它不会等待ajax调用完成.回调将帮助您管理它,因为它将在ajax返回时被调用.
我仍然是Ext的新手,但至少这是我的理解.希望它有所帮助,或者至少以正确的方式指出你.
编辑,因为我提醒说,有时在成功中返回将使调试变得困难等等.所以你也可以尝试改变你的成功来调用另一个函数并让该函数进行处理,只需记住范围.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。