Aurelia中的Switch语句

问题描述 投票:1回答:1

如何在Aurelia中调用函数并将参数传递给switch语句?这是我的示例:

home.html

<template>
<input type="text" value.bind="FruitName">
<div class="Fruit">
<a href="http://www.example.com/${TypeOfFruit(FruitName)}" target="_blank"><a>
</template>

home.js

export class Home {

  TypeOfFruit(fruits) {
    text = ""
    switch (fruits) {
      case "Banana":
        text = "Banana is good!";
        break;
      case "Orange":
        text = "I am not a fan of orange.";
        break;
      case "Apple":
        text = "How you like them apples?";
        break;
      default:
        text = "I have never heard of that fruit...";
    }
    return this.text;
  }
}
javascript aurelia
1个回答
0
投票

您需要的是value-converter,这些是特殊功能,可以在绑定时使用所需的任何逻辑(包括switch)来转换数据。

© www.soinside.com 2019 - 2024. All rights reserved.