在我的应用程序中,我使用 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调用之前刷新或清除列表。请帮助解决