2

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

<!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'; });

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

4

1 回答 1

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';
于 2013-04-06T20:39:47.583 回答