我在从 Telerik UI 显示 Nativescript 免费库的 RadListView 时遇到问题。我实现了入门指南中的示例:http: //docs.telerik.com/devtools/nativescript-ui/Controls/NativeScript/ListView/getting-started
XML:
<Page loaded="onPageLoaded" xmlns:lv="nativescript-telerik-ui/listview" xmlns="http://www.nativescript.org/tns.xsd">
<lv:RadListView items="{{ dataItems }}" >
<lv:RadListView.listViewLayout>
<lv:ListViewLinearLayout scrollDirection="Vertical"/>
</lv:RadListView.listViewLayout>
<lv:RadListView.itemTemplate>
<StackLayout orientation="vertical">
<Label fontSize="20" text="{{ itemName }}"/>
<Label fontSize="14" text="{{ itemDescription }}"/>
</StackLayout>
</lv:RadListView.itemTemplate>
</lv:RadListView>
</Page>
代码隐藏:
import viewModel = require("./getting-started-model");
export function onPageLoaded(args){
var page = args.object;
page.bindingContext = new viewModel.ViewModel();
}
模型:
import {ObservableArray} from "data/observable-array";
import timer = require("timer");
export class ViewModel {
private _items: ObservableArray<DataItem>;
private _words = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"];
constructor() {
}
get dataItems() {
if (!this._items) {
this._items = new ObservableArray<DataItem>();
for (var i = 0; i < 10; i++) {
this._items.push(new DataItem(i, "Item " + i, "This is item description."));
}
}
return this._items;
}
private getRandomLengthString(){
var sentenceLength = Math.round((Math.random() * 15));
var result = this._words[0];
for (var i = 0; i < sentenceLength; i++){
result += (this._words[i % this._words.length] + " ");
}
return result;
}
}
export class DataItem {
public id: number;
public itemName;
public itemDescription;
constructor(id: number, name: string, description: string) {
this.id = id;
this.itemName = name;
this.itemDescription = description;
}
}
但我得到的只是空白页..我使用的是 NS 版本 2.3.0
我究竟做错了什么?