Nativescript-ui Radlistview 空指针错误
Nativescript-ui Radlistview Null pointer error
Radlistview 未呈现源数组。请帮我弄清楚我要去哪里 wrong.This 给我空指针异常。我已将代码包含在下面的部分中。
srtdetails.component.html
<GridLayout tkExampleTitle tkToggleNavButton>
<RadListView [items]="source">
<template tkListItemTemplate let-item="item">
<ScrollView>
<StackLayout orientation="vertical">
<GridLayout class="srtgrid border" rows="auto" columns=" *, *, *">
<Label class="srtlabel " row="0" col="0" textWrap="true" [text]="item.requestid" ></Label>
<Label class="srtlabel " row="1" col="1" textWrap="true" [text]="item.requestedon" ></Label>
<Label class="srtlabel " row="2" col="2" textWrap="true" [text]="item.requesttype" ></Label>
</GridLayout>
</StackLayout>
</ScrollView>
</template>
</RadListView>
</GridLayout>
strdetails.component.ts
import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
...
@Component({
selector: "vp-srt-list",
moduleId: module.id,
templateUrl: './srtdetails.component.html',
styleUrls: ["./srtdetails.component.css"],
providers: [LoginService,NativeScriptUIListViewModule]
})
export class SrtListComponent implements OnInit{
public source: Array<any>;
constructor( private router: Router,
private LoginService: LoginService,
private routerExtensions: RouterExtensions){}
ngOnInit(){
this.source = this.LoadSrt();
}
LoadSrt(): Array<any>{
if (getConnectionType() === connectionType.none) {
alert("Oops!! looks like your device is not connected to the internet ");
return;
}
this.LoginService.getAssociatedRequest()
.subscribe((response: Array<any>) => {
//let data = JSON.stringify(response)
this.source = response;
console.log ("Response: " +this.source);
return this.source;
},
(error) => { console.log("Error happened", error.message)},
() => { console.log("srt is completed")
return this.source;
}
);
}
}
login.service.ts
getAssociatedRequest(){
let headers = new Headers();
return this.http.get(
BackendService.requestUrl
)
.map((response) => {
return response.json();
// console.log("JSON BODY: ",JSON.stringify(body));
}
)
.catch(this.handleErrors);
}
将 <RadListView [items]="source">
换成 <RadListView [items]="source" *ngIf="source">
。这样,它在有数据之前不会呈现,并且会在源有数据后立即填充
Radlistview 未呈现源数组。请帮我弄清楚我要去哪里 wrong.This 给我空指针异常。我已将代码包含在下面的部分中。
srtdetails.component.html
<GridLayout tkExampleTitle tkToggleNavButton>
<RadListView [items]="source">
<template tkListItemTemplate let-item="item">
<ScrollView>
<StackLayout orientation="vertical">
<GridLayout class="srtgrid border" rows="auto" columns=" *, *, *">
<Label class="srtlabel " row="0" col="0" textWrap="true" [text]="item.requestid" ></Label>
<Label class="srtlabel " row="1" col="1" textWrap="true" [text]="item.requestedon" ></Label>
<Label class="srtlabel " row="2" col="2" textWrap="true" [text]="item.requesttype" ></Label>
</GridLayout>
</StackLayout>
</ScrollView>
</template>
</RadListView>
</GridLayout>
strdetails.component.ts
import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
...
@Component({
selector: "vp-srt-list",
moduleId: module.id,
templateUrl: './srtdetails.component.html',
styleUrls: ["./srtdetails.component.css"],
providers: [LoginService,NativeScriptUIListViewModule]
})
export class SrtListComponent implements OnInit{
public source: Array<any>;
constructor( private router: Router,
private LoginService: LoginService,
private routerExtensions: RouterExtensions){}
ngOnInit(){
this.source = this.LoadSrt();
}
LoadSrt(): Array<any>{
if (getConnectionType() === connectionType.none) {
alert("Oops!! looks like your device is not connected to the internet ");
return;
}
this.LoginService.getAssociatedRequest()
.subscribe((response: Array<any>) => {
//let data = JSON.stringify(response)
this.source = response;
console.log ("Response: " +this.source);
return this.source;
},
(error) => { console.log("Error happened", error.message)},
() => { console.log("srt is completed")
return this.source;
}
);
}
}
login.service.ts
getAssociatedRequest(){
let headers = new Headers();
return this.http.get(
BackendService.requestUrl
)
.map((response) => {
return response.json();
// console.log("JSON BODY: ",JSON.stringify(body));
}
)
.catch(this.handleErrors);
}
将 <RadListView [items]="source">
换成 <RadListView [items]="source" *ngIf="source">
。这样,它在有数据之前不会呈现,并且会在源有数据后立即填充