Javascript
var pageData = new Observable({
appointmentsList: appointmentsList,
user_role: ''
});
exports.onLoaded = function (args) {
page = args.object;
page.bindingContext = pageData;
pageData.set('user_role', appSettings.getString('role'));
XML
<Repeater items="{{appointmentsList.booking_dates.bookings}}">
<Repeater.itemsLayout>
<StackLayout class="appointment-rows" />
</Repeater.itemsLayout>
<Repeater.itemTemplate>
<StackLayout>
<WrapLayout visibility="{{ user_role === 'agency' ? 'visible' : 'collapse' }}">
<Label text="{{user_name}}" class="row-client-name row-client-name-new" />
</WrapLayout>
</StackLayout>
</Repeater.itemTemplate>
</Repeater>
在上面的代码片段中,问题是我无法访问 Repeater
中的 user_role
。
谁能帮我如何访问 Repeater
中的外部元素?
谢谢。
最佳答案
基于此https://docs.nativescript.org/core-concepts/data-binding#example-4-creating-listview-child-items-based-on-the-itemtemplate ,你可以尝试这样的事情:
<WrapLayout visibility="{{$parents['Repeater'].user_role,$parents['Repeater'].user_role === 'agency' ? 'visibile' : 'collapse' }}">
或者这样
<WrapLayout visibility="{{$parents['Page'].user_role,$parents['Page'].user_role === 'agency' ? 'visibile' : 'collapse' }}">
关于javascript - 如何访问中继器内的外部元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41177597/