在我的应用程序中使用Ext.List显示JSON中的内容,初始JSON数据显示正确。如果我添加搜索关键字,JSON结果的响应将添加先前的内容,即
最初的表
Car
Bus
Jeep
如果我正在搜索Car,则表格如下所示
Car
Bus
Jeep
Car
但我想只显示新结果,这里是代码
搜寻
{
xtype: 'button',
ui:'normal',
width:'20%',
text: 'Search',
handler: function()
{
App.gvars.keywd=Ext.getCmp("searchfd").getValue();
searchfriends();
Ext.StoreMgr.get('searchfriendslist1').load();// i have added the method to refresh table but no use
}
}
搜索表
var searchfrieandtab= Ext.create('Ext.List', {
width: 320,
height: 290,
id : 'searchfriendslist1',
itemTpl: ['<div style="margin:0px;background:#fff;" >'+
'<table style="margin:0px;padding:0px;height:40px;" width="100%" >'+
'<tr><td style="padding:2px 5px;width:90%;"><span><img src="data:image/jpeg;base64,{userImage}"/>'+
'</span><span>{userFirstName}</span></td>'+
'<td style="padding:2px 10px;width:10%;">'+
'<img src="resources/img/addplus.png" onclick="invitefriends(\'{userId}\')"/>'+
'</td></tr></table></div>'].join(),
listeners : {
itemtap: function (list, index, item, record, senchaEvent) {
if (senchaEvent.event.target.nodeName == 'IMG') {
var data = record.getData();
var userId = data.userId;
var itemPurchased = data.itemPurchased;
invitefriends(userId);
}
}
}
});
JSON
function searchfriends() {
alert(App.gvars.keywd);
Ext.Ajax.request({
url: App.gvars.apiurl + 'SearchFriends/userID='+App.gvars.userid+'/keywords='+App.gvars.keywd,
method: "GET",
useDefaultXhrHeader: false,
withCredentials: true,
success: function (response) {
var respObj = Ext.JSON.decode(response.responseText);
Ext.getCmp('searchfriendslist1').setData(respObj.searchFriends);
},
failure: function (response) {
var respObj = Ext.JSON.decode(response.responseText);
Ext.Msg.alert("Error",response.responseText);
}
});
}
如何在JSON调用之前刷新或清除列表。请帮助解决
答案 0 :(得分:1)
试试这个:
searchfrieandtab.getStore().removeAll();