javascript - 如何访问中继器内的外部元素?

标签 javascript xml observable nativescript telerik-appbuilder

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/

相关文章:

xml - Powershell xml访问 key 对值

angular - observables 中的promise<void> 等价于什么?

android - 当数据是字符串而不是对象时,如何在 android 中使用解析相同的 json 响应?

javascript - AngularJS 指令变量在插值为变量之前解释为文本

javascript - javascript中的正则表达式如何查找两个 "special"字符之间的内容?

javascript - 如何在javascript中为函数名称附加两个字符串或数字

xml - XQuery 特定目录下的所有文件?

xml - SVG 问题 : AttValue: "or ' expected

javascript - 是否有类似于 John Papa 的 Angular JS 代码指南的深入 React JS 代码指南?

angular - 如何以 Angular 4 返回 Observable?