2

ここにあるコードをたどろうとしました:

component_created_in_code_test.html

component_created_in_code.dart

しかし、依存関係を取得して dartium でコードを実行すると、次のエラーが発生します。このエラーは、(.dart コードで) ComponentItem の create() メソッドを呼び出すときに発生します。

Breaking on exception: Class 'SayHello' has no instance method 'created_autogenerated'.

私はそれらを以下に少しだけ書き直しました(メインがインラインではなくダーツコードに移動されたことを除いて、コードは同じです):

<!-- component_created_in_code_test.html -->
<!doctype html>
<!--
Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
for details. All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <script src="packages/web_ui/testing/testing.js"></script>
</head>
<body>
  <element name="say-hello">
    <template>Hello {{name}}!</template>
    <script type='application/dart' src="component_created_in_code.dart">
    </script>
  </element>
  <say-hello name="component create in html"></say-hello>
</body>
</html>

そして次のダーツコード、

//component_created_in_code.dart

library component_created_in_code;

import 'dart:async';
import 'dart:html';
import 'package:web_ui/web_ui.dart';

class SayHello extends WebComponent {
  String name;
}

void main() {
  Timer.run(() {
    var hello = new SayHello()
    ..host = new DivElement()
    ..name = 'component created in code';

    // "hello" is the DOM node.
    // "hello.xtag" is your SayHello object.
    // We are working on making these be the same object.

    // If the component uses data-binding, we need to make sure the
    // "lifecycle" methods get called. We are working to make this be
    // automatic too.
    var lifecycleCaller = new ComponentItem(hello)..create();
    document.body.nodes.add(hello.host);
    lifecycleCaller.insert();
    window.postMessage('done', '*');
  });
}

この dart-lang の例には問題があるようです。何か不足していますか、それともコードが壊れていますか?


この質問に答えた後、問題に対する実用的なソリューションをパッケージ化しました。

component_created_in_code

git からプルして、dartEditor にインポートするだけです。次に、エディタから 'pub install' と 'reanalyze source' (絶対に問題ありません) を実行し、"web/component_created_in_code.html" の "Run in Dartium" を右クリックします。

4

2 に答える 2

1

最初に Web UI コンパイラーを実行する必要があるようです。HTML ファイルで packages/web_ui/dwc.dart を実行するか、次の行に沿って build.dart を記述します。

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

void main() {
  build(new Options().arguments, ['web/component_created_in_code_test.html']);
}
于 2013-06-10T17:58:55.463 に答える