Javascript 在ionic 2问题中获取Rss提要
请注意,我在尝试使用Ionic Framework 2解析rss提要时遇到了一些问题。当我运行代码时,它返回一个错误:无法读取未定义的属性“title”。你能帮我吗 项目github存储库 reddits-service.ts reddits.tsJavascript 在ionic 2问题中获取Rss提要,javascript,android,html,angularjs,ionic2,Javascript,Android,Html,Angularjs,Ionic2,请注意,我在尝试使用Ionic Framework 2解析rss提要时遇到了一些问题。当我运行代码时,它返回一个错误:无法读取未定义的属性“title”。你能帮我吗 项目github存储库 reddits-service.ts reddits.ts import { Component } from '@angular/core'; import { NavController, NavParams } from 'ionic-angular'; imp
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {RedditService} from '../../providers/reddit-service';
import {DetailsPage} from '../details/details' ;
/*
Generated class for the Reddits page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-reddits',
templateUrl: 'reddits.html'
})
export class RedditsPage {
items:any;
feeds:any;
posts:any;
constructor(public redditservice:RedditService, public navCtrl: NavController, public navParams: NavParams) {
}
ngOnInit(){
this.getPost();
}
getPost(){
this.redditservice.getPost().subscribe(response =>{
console.log(response);
this.items = response.feed.entry;
})
}
viewItem(item){
this.navCtrl.push(DetailsPage,{
item:item
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad RedditsPage');
}
}
reddits.html
您已经在此处将items数组设置为
response.feed.entity
:
this.items = response.feed.entry;
除非json具有嵌套的实体值,否则html应具有:
<h2>{{item.title}}</h2>
{{item.title}
您是否记录了数据。。项目中的条目可能为空。数据不为空。它已被记录。我可以看到它返回的内容,但当我尝试导航到它时,它会显示用户未定义。这肯定是对象的解析问题。。人们可以告诉你,如果你张贴的日志object@suraj请查找随附的日志文件和代码,我无法在这里真正说出对象结构。。尝试console.log(JSON.stringify(items,undefined,2))
我尝试了你的建议,结果显示为[object][object]除此之外我不确定。你可能需要调试哇…好的,你能在业余时间看看ripo吗请@Suraj我想使用这个博客url有一个解决办法,因为我只是使用reddit api应用了相同的代码,它工作了。谢谢
Objectencoding: "UTF-8"feed: Objectauthor: Array[1]category:
Array[6]entry:
Array[25]generator:
Objectid: Objectlink:
Array[5]openSearch$itemsPerPage:
ObjectopenSearch$startIndex:
ObjectopenSearch$totalResults:
Objectsubtitle: Objecttitle:
Objectupdated: Objectxmlns: "http://www.w3.org/2005/Atom"xmlns$blogger: "http://schemas.google.com/blogger/2008"xmlns$gd: "http://schemas.google.com/g/2005"xmlns$georss: "http://www.georss.org/georss"xmlns$openSearch: "http://a9.com/-/spec/opensearchrss/1.0/"xmlns$thr: "http://purl.org/syndication/thread/1.0"__proto__: Objectversion: "1.0"__proto__: Object
error_handler.js:47 EXCEPTION: Error in ./RedditsPage class RedditsPage - inline template:34:4 caused by: Cannot read property 'title' of undefined
ErrorHandler.handleError @ error_handler.js:47
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
**error_handler.js:49 ORIGINAL EXCEPTION: Cannot read property 'title' of undefined**
ErrorHandler.handleError @ error_handler.js:49
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:52 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:52
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:53 TypeError: Cannot read property 'title' of undefined
at View_RedditsPage1.detectChangesInternal (/AppModule/RedditsPage/component.ngfactory.js:234)
at View_RedditsPage1.AppView.detectChanges (view.js:288)
at View_RedditsPage1.DebugAppView.detectChanges (view.js:381)
at ViewContainer.detectChangesInNestedViews (view_container.js:45)
at CompiledTemplate.proxyViewClass.View_RedditsPage0.detectChangesInternal (/AppModule/RedditsPage/component.ngfactory.js:120)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:288)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:381)
at CompiledTemplate.proxyViewClass.View_RedditsPage_Host0.detectChangesInternal (/AppModule/RedditsPage/host.ngfactory.js:29)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:288)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:381)
ErrorHandler.handleError @ error_handler.js:53
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:56 ERROR CONTEXT:
ErrorHandler.handleError @ error_handler.js:56
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:57 DebugContext {_view: View_RedditsPage1, _nodeIndex: 3, _tplRow: 34, _tplCol: 4}
ErrorHandler.handleError @ error_handler.js:57
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
this.items = response.feed.entry;
<h2>{{item.title}}</h2>