使用单选按钮和Web UI进行数据绑定

时间:2013-04-06 17:32:55

标签: dart dart-webui

我无法使用无线电输入获得以下数据绑定代码:

<!DOCTYPE html>

<html>
  <body>
    <div>
      <input type="radio" name='veggies' value="kale" bind-value={{name}}>Kale<br>
      <input type="radio" name='veggies' value="spinach" bind-value={{name}}>Spinach<br>
      <input type="radio" name='veggies' value="carrots" bind-value={{name}}>Carrots
    </div>

    <p>name = {{name}}</p>

    <script type="application/dart">

      import 'package:web_ui/web_ui.dart';

      @observable
      String name = "Carrots";

      void main() {}

    </script>
  </body>
</html>

该文件是radio_binding.html。

当我构建此文件时,我在out / radio_binding.html.dart文件中收到错误:

Error: line 42 pos 46: semicolon expected
  __t.listen(__e0.onChange, ($event) { {{name}} = 'kale'; });

这是一个错误还是我做错了什么?

1 个答案:

答案 0 :(得分:4)

尝试使用此绑定:

<div>
  <input type="radio" name='veggies' value="Kale" bind-value="name">Kale<br>
  <input type="radio" name='veggies' value="Spinach" bind-value="name">Spinach<br>
  <input type="radio" name='veggies' value="Carrots" bind-value="name">Carrots
</div>

我认为你不需要@observable,我只是用过:

String name = 'Spinach';