1
我正在Sencha Touch中开发移动应用程序,并且需要在本地存储以前搜索的详细信息而不会有重复。Sencha Touch商店中的唯一值
搜索,存储和显示工作正常,但是如果我做了两次相同的搜索,则条目会在我的商店中重复。
我预计商店的“ID”会这样做,但有些东西似乎是错误的。
这是商店的代码。
Ext.regModel('sSaved', {
fields: [
{name: 'IDs', type: 'int'},
{name: 'Outward', type: 'string'},
{name: 'Return', type: 'string'},
{name: 'Pickup', type: 'string'},
{name: 'Destination', type: 'string'}
],
proxy: {
type: 'localstorage',
id:'IDs'
}
});
var savedJobs = new Ext.DataView({
store: new Ext.data.Store({
model: 'sSaved',
storeId: 'allSaved'
}),
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<table class="item" style="margin:auto;">',
'<tr><td class="title">ID</td><td>{IDs}</td></tr>',
'<tr><td class="title">Outward</td><td>{Outward}</td></tr>',
'<tr><td class="title">Return</td><td>{Return}</td></tr>',
'<tr><td class="title">Pickup</td><td>{Pickup}</td></tr>',
'<tr><td class="title">Destination</td><td>{Destination}</td></tr>',
'</table>',
'</tpl>'
),
itemSelector: "table.item",
autoHeight:true,
emptyText: 'No Saved Jobs',
autoLoad: true
});
并设置商店的代码。
var fetched = Ext.decode(result.responseText);
var details = fetched.apiResponse.details;
savedJobs.store.load();
savedJobs.store.add({
"IDs":details.ID,
"Outward":details.Outward,
"Return":details.Return,
"Pickup":details.Pickup,
"Destination":details.Destination
});
savedJobs.store.sync();
我可以解决此通过某种方式搜索商店,并检查是否添加前值存在,但我敢肯定有一个更简单的方法。
如果这个search-> check-> add是需要的方法,那么资源密集度最低的方法是什么?