Skip to content

ListView: Inconsistency retrieving bindingContext in tap handler #940

Closed
@tjvantoll

Description

@tjvantoll

This is a small issue that has tripped me up before, and which was also reported to me on Twitter. The syntax to get the bindingContext in a list view item's tap handler varies based on the type of element you use. Here's a short example:

<Page loaded="loaded">
    <ListView items="{{ myList }}">
        <ListView.itemTemplate>
            <StackLayout>
                <Button tap="buttonTap" text="Hi, I'm a button" />
                <Label tap="labelTap" text="Hi, I'm a label" />
            </StackLayout>
        </ListView.itemTemplate>
    </ListView>
</Page>
var observableModule = require("data/observable");
var observableArrayModule = require("data/observable-array");

var pageData = new observableModule.Observable({
    myList: new observableArrayModule.ObservableArray(["foo", "bar"])
});

exports.loaded = function(args) {
    var page = args.object;
    page.bindingContext = pageData;
};

exports.buttonTap = function(args) {
    console.log(args.object.bindingContext);
};
exports.labelTap = function(args) {
    console.log(args.view.bindingContext)
};

The thing to notice here is that buttonTap uses args.object.bindingContext, whereas labelTap uses args.view.bindingContext to get a reference to the same data.

It seems like the API should be the same regardless of what type of UI component you use. A consistent approach would also make it far easier to share code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy