1

参考此链接https://docs.nativescript.org/core-concepts/data-binding#supported-expressions

function calls  myFunc(var1, var2, ..., varN)   Where myFunc is a function available in binding context (used as context for expression) or within application level resources. The value of the var1 and varN will be used as parameter(s).

我使用一个 RadList,其中每个项目我都有一个标签,我需要在其中显示一个组合字符串,检查基于项目参数的复杂逻辑。

谁能给出打字稿示例我们如何使用函数调用。我尝试了很多方法,但没有任何效果。

4

2 回答 2

0

正如 Culita 建议的那样 - 使用 $parent 应该可以工作,但事实并非如此。这对我来说似乎是一个错误,请确保在相应的 GitHub 存储库中打开一个关于它的新问题。

作为一种解决方法,您可以在用于将模板绑定到的类型中创建函数。在这种情况下 - 它按预期工作:

class Location {
    constructor(city: string, country: string, imageSrc: string) {
        this.city = city;
        this.country = country;
        this.imageSrc = imageSrc;
    }

    city: string;
    country: string;
    imageSrc: string;

    getLabel(args): string {
        return "a" !== args ? "My label" + args : "Your Label ? " + args;
    }
}

看看修改后的 Playground

于 2019-09-25T08:24:05.480 回答
0

创建一个函数,然后您可以通过将元素的属性绑定到它来自由使用它。

getLabel(args): string {
    return "a" !== args ? "My label" + args: "Your Label ? " + args;
}


<Label text="{{ getLabel('dynamic') }}" class="lbl" textWrap="true" />
于 2019-09-19T20:30:56.203 回答