3
我有一個<select>
標籤有幾個選項。如何設置最初默認選擇的選項?如何在Web UI <select>標籤中設置默認選定選項?
我有一個<select>
標籤有幾個選項。如何設置最初默認選擇的選項?如何在Web UI <select>標籤中設置默認選定選項?
這裏是飛鏢代碼:
import 'dart:html';
import 'package:web_ui/web_ui.dart';
List<String> fruits = const <String>['apples', 'bananas', 'pears'];
@observable
String selected = 'pears';
void main() { }
下面是HTML代碼:
<p>Hello world from Dart! You chose {{ selected }}</p>
<select name="fruit" template iterate="fruit in fruits" bind-value="selected">
<option selected="{{selected == fruit}}">{{fruit}}</option>
</select>
注意,有一個open request使之成爲一個更容易一些。同時,上面的代碼應該適合你。