我可以在布局中添加 ListView 吗?
我有这个 View :
function pageLoaded(args) {
var page = args.object;
var array = new observableArray.ObservableArray();
array.push({"city":"Madrid","distance":"0.2km","votes":"0"});
array.push({"city":"Madrid","distance":"0.2km","votes":"0"});
array.push({"city":"Madrid","distance":"0.2km","votes":"0"});
array.push({"city":"Madrid","distance":"0.2km","votes":"0"});
array.push({"city":"Madrid","distance":"0.2km","votes":"0"});
array.push({"city":"Madrid","distance":"0.2km","votes":"0"});
page.bindingContext = vmModule.mainViewModel, {"myItems": array};
};
exports.pageLoaded = pageLoaded;
这个模板:
<GridLayout>
<TabView>
<TabView.items>
<TabViewItem title="Nearest Wifi">
<TabViewItem.view>
<GridLayout>
<ListView items="{{ myItems }}">
<ListView.itemTemplate>
<GridLayout columns="*,*" rows="2">
<Label col="0" row="0" text="{{ city || 'Downloading...' }}" textWrap="true" class="title" />
<Label col="1" row="0" text="{{ distance || 'Downloading...' }}" textWrap="true" class="title" />
<Label col="0" row="1" colspan="2" text="Votes: {{nr_votes | 0 }}"/>
</GridLayout>
</ListView.itemTemplate>
</ListView>
</GridLayout>
</TabViewItem.view>
</TabViewItem>
...
我尝试让它工作 3 个小时..任何帮助将不胜感激。谢谢!
最佳答案
这段代码运行良好,我相信这就是您所追求的:
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">
<ActionBar title="Cities - WIFI" />
<TabView>
<TabView.items>
<TabViewItem title="Nearest Wifi">
<TabViewItem.view>
<ListView items="{{ cities }}">
<ListView.itemTemplate>
<GridLayout columns="*,*,*" rows="*,*">
<Label col="0" row="0" text="City"/>
<Label col="1" row="0" text="Distance" />
<Label col="2" row="0" text="Votes" />
<Label col="0" row="1" text="{{city}}" />
<Label col="1" row="1" text="{{distance}}" />
<Label col="2" row="1" text="{{votes}}" />
</GridLayout>
</ListView.itemTemplate>
</ListView>
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
</Page>
Javascript:
var Observable = require("data/observable").Observable;
var ObservableArray = require("data/observable-array").ObservableArray;
function pageLoaded(args) {
var page = args.object;
page.bindingContext = pageData;
}
exports.pageLoaded = pageLoaded;
var pageData = new Observable({
cities: new ObservableArray([
{city:"Madrid", distance:"0.2km",votes:"0"},
{city:"Madrid", distance:"0.2km",votes:"0"},
{city:"Madrid", distance:"0.2km",votes:"0"}
])
})
关于javascript - Nativescript ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34696458/