dart - web-ui 2路数据绑定(bind)

标签 dart

我是 dart 新手。

我试图构建 web-ui example在塞思·拉德的博客上。我创建了一个新应用程序。

我的 html 看起来像这样:

<!DOCTYPE html>
<html> 

  <head> 
    <meta charset="utf-8"> 
    <title>Proefje</title> 
    <link rel="stylesheet" href="Proefje.css"> 
  </head> 

  <body> 

    <h1>Hello MDV</h1> 
    <p>MDV is {{superlative}}</p> 
    <button id="change-it" on-click="changeIt()">Change</button> 

    <script type="application/dart" src="Proefje.dart"></script> 
    <script src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script> 
  </body> 
</html>

Dart 代码如下:

import 'dart:math';
import 'dart:html'; 
import 'package:web_ui/web_ui.dart'; // not sure about this line

String superlative; 
List<String> alternatives = const ['wicked cool', 'sweet', 'fantastic']; 
Random random; 

main() { 
  superlative = 'awesome'; 
  random = new Random(); 
  query('#change-it').text = 'Do Change'; 
} 

changeIt() => superlative = alternatives[random.nextInt(alternatives.length)];

还有我的 pubspec.yaml

name:  Proefje
description:  A sample application 

dependencies:   
  web_ui: any

当我运行应用程序时,我看到查询函数更改了按钮中的文本,但 MDV is {{superlative}} 保持原样。

有什么想法吗?

最佳答案

您需要按照 Seth Ladd 博客的设置部分中所述编译 html。

If you're new to Dart Web Components, you might want to read my Your First Web Component with Dart post, or the Dart Web Components article. Just like Dart Web Components, for MDV to work you need to get the web_components package, which contains the dwc compiler. The compiler is what converts the MVC and WC code into vanilla Dart and HTML.

基本上,您可以在根目录中添加 build.dart ,内容如下:

import 'package:web_ui/component_build.dart';
import 'dart:io';

void main() {
  build(new Options().arguments, ['web/App.html']);
}

(参见 Tools for Web UI )

关于dart - web-ui 2路数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13827771/

相关文章:

dart - 是否必须将CustomEvent扩展为自定义DOM事件?

json - dart,是否可以将功能反序列化到json/从json反序列化?

android - 即使应用程序被终止,flutter_background_geolocation 也会获取位置吗?

css - 直接在 polymer 中设计元素样式是不好的做法吗?

dart - 子字符串直到字符串中第一次出现逗号

dart - Flutter 应用程序中图像显示和用户 react 的准确时间

flutter - 如何执行 future 的单次执行?

json - Flutter从Rest API解析.JSON

flutter - 如何将新的 launchUrl() 方法与 "mailto:"链接一起使用?

networking - flutter/Dart : List devices on local network