我有一个PhoneGap应用程序,它显示一个RSS提要。我使用本地存储为用户保存一个最喜欢的类别,并在应用程序加载时从本地存储中调用它。然而,当应用程序第一次安装时,它应该显示一般的RSS提要。由于某些原因,RSS提要显示为空白,直到选择了一个类别。然后,当重新加载应用程序时,它可以正常工作。有人能帮忙吗?谢谢!
这里是我必须检查当地仓库的东西:
//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发布于 2014-02-20 20:39:10
var URL = localStorage.getItem('url') || 'http://www.RssUrlHere.com';||是OR算子。它从左开始计算,如果最左边的值是falsy值,则结果将是右侧的结果。
同样,当使用未定义的时,格式也不同。
if(typeof x === "undefined"){
}var title = "General";
switch(URL){
case 'http://www.RssUrlHere.comB' :title="Bioengineering"; break;
case 'http://www.RssUrlHere.comC' :title="dfsfsdf"; break;
case 'http://www.RssUrlHere.comD' :title="sdfsdf"; break;
case 'http://www.RssUrlHere.comE' :title="sdfsdf"; break;
case 'http://www.RssUrlHere.comF' :title="sdfsdfsdfsdf"; break;
case 'http://www.RssUrlHere.comG' :title=""; break;
case 'http://www.RssUrlHere.comH' :title="sdfsdf"; break;
case 'http://www.RssUrlHere.comI' :title="sdfsdfsdf"; break;
default : title = "Unknown Title";
}
$('#header-title').html(title);
$('#event-title').html(title);发布于 2014-02-20 20:38:09
试着使用
if (!typeof rssURL == "undefined" || rssURL !== "null") { URL = rssURL }而不是
if (rssURL !== "undefined" || rssURL !== "null") { URL = rssURL }https://stackoverflow.com/questions/21918942
复制相似问题