繁体   English   中英

如何使用离子框架从RSS feed显示图像

[英]How to show image from RSS feed using ionic framework

我只是在学习离子。 你可以帮助我解决这个问题吗,不知怎的,我无法在android中显示图片

我使用这个js代码从Rss feed获取数据

.controller("feedCtrl", function($http, $scope){$scope.init = function(){
$http.get("http://ajax.googleapis.com/ajax/services/feed/load", { params: { "v": "1.0", "num":"100", "q": "http://www.bola.net/feed/" } })
.success(function(data) {
    $scope.rssTitle = data.responseData.feed.title;
    $scope.rssUrl = data.responseData.feed.feedUrl;
    $scope.rssSiteUrl = data.responseData.feed.link;
    $scope.entries = data.responseData.feed.entries;
//  $scope.author = data.responseData.feed.author;
//  $scope.descriptionin = data.responseData.feed.description;
    //$scope.publishedDate = data.responseData.feed.publishedDate;
    //$scope.content = data.responseData.feed.content;
    //$scope.categories = data.responseData.feed.categories;
})
.error(function(data) {
    console.log("ERROR: " + data);
});}  $scope.browse = function(v){
window.open(v, "_system", "location=yes")}});

在我看来,我使用这个代码,

 <ion-content class="padding" ng-controller="feedCtrl" ng-init="init()">
    <div class="list">
      <a class="item" ng-href="{{entry.link}}" ng-click="window.open(this.href, '_blank', 'location=no'); return false;" ng-repeat="entry in entries">
        <b>{{entry.title}}</b><br/>
        <b>{{entry.link}}</b><br/>
        <b>{{entry.author}}</b><br/>
        <b>{{entry.publishedDate}}</b><br/>
        <b>{{entry.contentSnippet}}</b><br/>
        <b>{{entry.content}}</b><br/>
        <span ng-bind-html="entry.contentSnippet"></span>
      </a>
    </div>
</ion-content>

Android页面中条目内容的结果是这样的,

<img src="http://cdn.klimg.com/****.net/library/upload/20/2016/07/175/jose-mourinho_30eb505.jpg" align="left" hspace="5" width="100"/>Pelatih Manchester United Jose Mourinho mengungkapkan pasukannya sudah siap untuk menjalani laga menghadapi Galatasaray yang akan berlangsung di Gothenburg, Swedia, pada hari Sabtu (30/7).]]>

但我想要的只是图像的链接,

http://cdn.klimg.com/****.net/library/upload/20/2016/07/175/jose-mourinho_30eb505.jpg

我怎么能这样做?,谢谢

只需创建一个新函数,像这样提取src:

$scope.getPhoto = function(entry) {
    return entry.content.match(/src="([^"]*)/)[1];
}

然后更改: <b>{{entry.content}}</b><br/>

至: <b>{{getPhoto(entry)}}</b><br/>

所有Rss提要都不会提供图像,但像CNN这样的新闻频道会在索引媒体组中提供图片......

{{entry.mediaGroups[0].url }}

共有11张不同分辨率的图像......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM