2016-02-23 112 views
0

當按下按鈕時,我希望本地保存的按鈕的名稱和ID。Appcelerator商店本地搜索

我不太清楚解決這個問題的最好方法。我應該使用appcelerator屬性(http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.App.Properties)還是將文件寫入存儲?此刻我正在使用Ti.App.Properties.setList。

示例代碼:

searchStorageName = "searchHistory";  
searchResultsArray = []; 
var currentEntries = (Ti.App.Properties.getList(searchStorageName)); 

// Create search entry object. 
var localSearchObject = { 
    company_name: resultNodeCompany, 
    company_id: resultNodeCompanyID, 
    variation_id: resultNodeCompanyVariationID 
}; 
// Check if existing entries, if so push current search 
// and previous searches to array. 
if(currentEntries === null || currentEntries === undefined){ 
    searchResultsArray.push(localSearchObject); 
    Ti.App.Properties.setList(searchStorageName, searchResultsArray); 
    // searchResultsArray.push(localSearchObject, currentEntries); 
} 
else { 
    searchResultsArray.push(localSearchObject, currentEntries); 
    Ti.App.Properties.setList(searchStorageName, searchResultsArray); 
} 

我停留在此刻,因爲它是插入重複搜索到數組。當我遍歷這些值在UI中創建一個列表時,它會顯示重複項。

var currentEntries = (Ti.App.Properties.getList(searchStorageName)); 
var currentEntriesLength = currentEntries.length; 
var getPreviousHistorySearchesArray = []; 
currentEntries.forEach(function(entry, index) { 
    var company_name = entry.company_name; 
    var company_id = entry.company_id; 
    var variation_id = entry.variation_id; 

    // Create View Entry. 
    createSearchHistoryViewEntry(index, company_name, company_id, variation_id); 
} 
+0

更好,爲什麼不使用'SQLite_Database' http://docs.appcelerator.com/titanium/3.0/#!/guide/Working_with_a_SQLite_Database –

+1

我剛纔想使用SQLite,它工作得更好。謝謝你的提示。我對Android開發很陌生。 – Simon

+0

我會寫一個答案,請確認它是否正確,謝謝 –

回答