【发布时间】:2018-03-15 16:42:08
【问题描述】:
我收到了一些通过 RSS 新闻提要接收的数据,需要以 HTML 格式显示以用于 ionic 框架应用程序。有两个问题。我需要将' 和amp; 替换为'(撇号)和空格。
AngularJS:
$scope.rssItems = [];
var callbackI = 0;
for(var i=0; i<$marketProvider[$scope.currentMarket].rss.length; i+=1){
$webServicesFactory.get($marketProvider[$scope.currentMarket].rss[i], {Accept: "application/xml"}).then(
function success(xmlData) {
console.log("Home News: ", x2js.xml_str2json(xmlData));
if (x2js.xml_str2json(xmlData) == null)
$ionicLoading.hide();
$scope.rssItems = $scope.rssItems.concat(x2js.xml_str2json(xmlData).rss.channel.item);
// $scope.rssItems = $scope.rssItems.replace("amp;","");
callbackI+=1;
if(callbackI == $marketProvider[$scope.currentMarket].rss.length){
//console.info($scope.rssItems);
$ionicLoading.hide();
}
},
function error(error) {
$ionicLoading.hide();
}
);
和html
<div class="list">
<h5 class="item item-positive item-divider" align="justify">Today's Headlines</h5>
<span ng-if="rssItems.length==0">No news available.</span>
<div class="item item-thumbnail-left" ng-bind-html="rssItems(item)" ng-repeat="item in rssItems | orderBy: -dateOrder" ng-click="openNews(item.link)">
<img ng-src="{{item.enclosure._url || item.enclosure[0]._url || item.content._url || item.thumbnail._url || 'img/icon.png'}}">
<h2>{{item.title.replace("amp;","") | htmlToPlaintext}}</h2>
<p>{{item.pubDate | shortDate}}
<p>{{item.description | htmlToPlaintext}}</p>
</div>
-
<h2>{{item.title.replace("amp;","") | htmlToPlaintext}}</h2>可以正确替换,但<h2>{{item.title.replace("&#39;","'") | htmlToPlaintext}}</h2>无法替换为 aprotrophe。 - 我需要同时更换两个。
【问题讨论】:
标签: javascript html angularjs ionic-framework