0
我指的是JavaScript中的stack overflow答案,但我無法在角js上工作。按日期排序rss新聞與角js
JavaScript的答案排序的RSS根據日期饋送(最新頂部)是如下
data.query.results.rss.sort(function(item1, item2) {
var d1 = new Date(item1.channel.item.pubDate)
var d2 = new Date(item2.channel.item.pubDate)
return d2.getTime() - d1.getTime()
})
我的角的js(離子框架)是如下:
$webServicesFactory.get(
"https://www.google.com/finance/company_news",
{},
{
output: "rss",
q: stock.e +":"+ stock.t
}
).then(
function success(xmlData) {
var x2js = new X2JS();
$globalFactory.personalStockNews = x2js.xml_str2json(xmlData).rss.channel.item;
$globalFactory.personalStockNews.sort(function(item1, item2) {
var d1 = new Date(item1.channel.item.pubDate);
var d2 = new Date(item2.channel.item.pubDate);
return d2.getTime() - d1.getTime();
})
console.info($globalFactory.personalStockNews);
$ionicLoading.hide();
$state.go("app.home");
},
function error(error) {
$globalFactory.personalStockNews = null;
$ionicLoading.hide();
$state.go("app.home");
}
);
},
function error(error) {
$ionicLoading.hide();
}
);
但是,它沒有按預期排序。 我該如何將javascript修改爲angular js?
您可以使用下面的rss訂閱源 'https://www.google.com/finance/company_news?q=SGX:533&ei=EeiDWaGGMpXUuATxloPgAw&output=rss'根據日期對rss進行排序。
在HTML中,代碼如下:
<a class="item item-icon-right" ng-if='showmore' ng-repeat="item in rssNews| orderBy: 'pubDate':true" ng-click="openitems(item.link)">
<h2>{{item.title}}</h2>
<h6>{{item.pubDate}}</h6>
<p {{story.description | htmlToPlaintext}}</p>
</div>
</a>
嗨。我想對rss鏈接進行排序,就像stackoverflow示例一樣。但是,我無法對它進行角度js排序 – bkcollection
嘗試你的代碼,它仍然無法排序。也許你可以試試rss feed https://www.google.com/finance/company_news?q=SGX:533&ei=EeiDWaGGMpXUuATxloPgAw&output=rss – bkcollection
嗯,我發現有一件事是一個問題。我更新了我的答案。我懷疑你的原始排序功能實際上一旦你放棄ng重複功能。 –