我有一個顯示RSS提要的PhoneGap應用程序。我正在使用本地存儲爲用戶保存一個最喜歡的類別,並在應用程序加載時從本地存儲中調用它。但是,首次安裝應用程序時,應該顯示一般的RSS提要。 由於某種原因,RSS Feed在選擇類別之前爲空白。然後,當應用程序重新加載時,它工作正常。有人可以幫忙嗎?謝謝!如果本地存儲爲空或空的情況下如何顯示內容
這是我要檢查本地存儲:
//get local storage item
var rssURL = localStorage.getItem('url');
//set the URL for the ajax call in case there is no stored item
var URL = 'http://www.RssUrlHere.com';
//if the localstorage is undefined or null, use the general RSS url , if not get assign stored URL Note: also tried != to see if that made a difference, it did not.
if (rssURL !== "undefined" || rssURL !== "null") { URL = rssURL }
//comparing the URL with category URLs, works fine but clunky!
if(URL == 'http://www.RssUrlHere.comA') { $('#header-title').html("Bioengineering"); $('#event-title').html("Bioengineering");}
else if (URL == 'http://www.RssUrlHere.comB') { $('#header-title').html("Communications"); $('#event-title').html("Communications");}
else if (URL == 'http://www.RssUrlHere.comC') { $('#header-title').html("Electrical/Power"); $('#event-title').html("Electrical/Power");}
else if (URL == 'http://www.RssUrlHere.comD') { $('#header-title').html("Electronics Design"); $('#event-title').html("Electronics Design");}
else if (URL == 'http://www.RssUrlHere.comE') { $('#header-title').html("Nanoengineering"); $('#event-title').html("Nanoengineering");}
else if (URL == 'http://www.RssUrlHere.comF') { $('#header-title').html("Optics/Display"); $('#event-title').html("Optics/Display");}
else if (URL == 'http://www.RssUrlHere.comG') { $('#header-title').html("Semiconductors"); $('#event-title').html("Semiconductors");}
else if (URL == 'http://www.RssUrlHere.comH') { $('#header-title').html("Computers/Software"); $('#event-title').html("Computers/Software");}
else if (URL == 'http://www.RssUrlHere.comI') { $('#header-title').html("Technology Management"); $('#event-title').html("Technology Management");}
else { $('#event-title').html("All Events"); $('#header-title').html("Mobile");}
//My ajax call with for the URL
$.ajax({
type: 'GET',
url: URL,
dataType: 'xml',
success: function (xml) {
//functions here
釘了它!做得好!我不知道我可以編寫這樣的變量,所以謝謝你通知我! – Bacon2305
哇!謝謝你也幫助我!看起來更好,功能更好。真的很感激它。 – Bacon2305
很高興它幫助:) – sabithpocker