Referencing a views attributes in binding context moustache

ios

#1

Can you point to another attribute of the same view within a data binding xml moustache?

Say you had this xml;

<Switch id="option_1" checked="{{ options.selected_id === this.id ? true : false }}"/>
<Switch id="option_2" checked="{{ options.selected_id === this.id ? true : false }}"/>
<Switch id="option_3" checked="{{ options.option_3 }}"/>

So what I’m trying to do here is make it so if option_1 is selected option_2 is not.

I now i can hard code it by changing this.id to 'option_1'. But it would be good if you could reference the id attribute on the Switch view.


#2

@Mudlabs this will be undefined at run time. You can try Converters.

View

<Switch id="option_1" checked="{{ options.selected_id | verify('option_1') }}" />
<Switch id="option_2" checked="{{ options.selected_id | verify('option_2') }}" />
<Switch id="option_3" checked="{{ options.option_3 }}" />

Controller

import { EventData } from 'data/observable';
import { StackLayout } from 'ui/layouts/stack-layout';
import { HomeViewModel } from './home-view-model';

export function pageLoaded(args: EventData) {
    let page = <StackLayout>args.object;
    page.bindingContext = new HomeViewModel();
}

ViewModel

import { Observable } from 'data/observable';

export class HomeViewModel extends Observable {
    constructor() {
        super();
        this.set("options", {
            selected_id: "option_1",
            option_3: "Option 3"
        });
    }

    verify(value, id) {
        return value === id;
    }
}