我熟悉NativeScript但最近我试图在一个位于RadSideDrawer主内容中的TabView中实现一个ListView。在实现这一点时,我现在有点丢失了Observable数组并填充了ListView。我已经尝试过看教程,但我觉得我做错了什么,如果有人能调查并帮助我,我将非常感激。
这是我的代码:
landing.xml
<page
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:drawer="nativescript-telerik-ui/sidedrawer"
xmlns:widgets="common/widgets"
xmlns:notifications="pages/landing/notifications"
xmlns:requests="pages/landing/requests"
xmlns:alln="pages/landing/allnoti"
loaded="loaded">
<page.actionBar>
<actionBar title="iStart">
<!--- <action-bar.titleView>
<StackLayout orientation="horizontal" ios:horizontalAlignment="center" android:horizontalAlignment="left">
<!--<Image src="res://acicon" class="action-image" />
<Label text=" iStart" class="action-label" />
</StackLayout>
</action-bar.titleView> -->
<actionBar.actionItems>
<android>
<actionItem android.position="actionBarIfRoom" tap="toggleDrawer" icon="res://ic_menu" />
</android>
<ios>
<actionItem icon="res://ic_menu" ios.position="right" tap="toggleDrawer" />
</ios>
</actionBar.actionItems>
</actionBar>
</page.actionBar>
<drawer:rad-side-drawer id="newdrawer" drawerContentSize="180" drawerLocation="right">
<drawer:rad-side-drawer.mainContent>
<!-- Landing page contents -->
<TabView class="tabview-look" style="font-family: FontAwesome; font-size: 15;" selectedColor="blue">
<TabView.items>
<TabViewItem title=" All" >
<TabViewItem.view>
<alln:allnoti />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title=" Notifications" >
<TabViewItem.view>
<notifications:notifi />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title=" Requests" >
<TabViewItem.view>
<requests:request />
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
</drawer:rad-side-drawer.mainContent>
<drawer:rad-side-drawer.drawerContent>
<widgets:drawer-content />
</drawer:rad-side-drawer.drawerContent>
</drawer:rad-side-drawer>
</page>
landing.ts
import {BasePage} from "../../common/BasePage";
import {Observable, EventData} from "data/observable";
import {View} from "ui/core/view";
import observableM = require("data/observable");
import observableArrayModule = require("data/observable-array");
import {fromObject} from "data/observable";
let pageData = observableM.fromObject({
'notificationList': new observableArrayModule.ObservableArray([
{title: "Title1", body: "Body1"},
{title: "Title2", body: "Body2"}
])
});
let vm = new Observable();
class LandingPage extends BasePage{
mainContentLoaded(args:EventData){
//set the bindingContext for the LandingPage content here
let view = <View>args.object;
view.bindingContext = pageData;
}
}
export = new LandingPage();
allnoti.xml
<stack-layout loaded="onViewLoaded" unloaded="onViewUnloaded"
xmlns:lv="nativescript-telerik-ui/listview" >
<!-- entirety of the tab's content -->
<GridLayout>
<ListView items="{{notificationList}}">
<ListView.itemTemplate>
<stack-layout>
<label text="{{title}}" horizontalAlignment="left" verticalAlignment="center" />
<label text="{{body}}" horizontalAlignment="left" verticalAlignment="center" />
</stack-layout>
</ListView.itemTemplate>
</ListView>
</GridLayout>
</stack-layout>
我想在listview中有一个数据绑定,但由于层次结构,我真的很困惑。对不起,如果这是一个新手问题,希望有人可以提供帮助。
答案 0 :(得分:0)
看来,添加mainContentLoaded解决了这个问题。
<TabView class="tabview-look" style="font-family: FontAwesome; font-size: 15;" selectedColor="blue" loaded="mainContentLoaded">