1

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>

上記のスニペットでは、問題はuser_role内部にアクセスできないことですRepeater。内部の外側の要素にアクセスする方法を教えてくれる人はいますRepeaterか?

ありがとう。

4

2 に答える 2

3

この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' }}">
于 2016-12-16T06:47:50.373 に答える
1

$parentまたは$parents[]プロパティを使用する必要があります。

私は信じている:

<WrapLayout visibility="{{ $parent.user_role, $parent.user_role === 'agency' ? 'visible' : 'collapse' }}">

動作するはずです。ただし、これはリピーターにあるため、親バインディングに奇妙なことは何もないと思います。しかし、それがうまくいかない場合は、次のように簡単に実行できます。 <WrapLayout visibility="{{ $parents['Page'].user_role, $parents['Page'].user_role === 'agency' ? 'visible' : 'collapse' }}">

この機能に関する NativeScript ドキュメント: http://docs.nativescript.org/core-concepts/data-binding#binding-to-a-parent-binding-context

于 2016-12-16T06:50:18.440 に答える