2

次のエラーが発生します。

Stack Trace: #0      NoSuchMethodErrorImplementation._throwNew (dart:core-patch:641:3)
#1      init_autogenerated (http://127.0.0.1:3030/C:/dev/CalendarDatePicker/CalendarDatePicker/web/out/CalendarDatePicker.dart:43:26)
#2      main (http://127.0.0.1:3030/C:/dev/CalendarDatePicker/CalendarDatePicker/web/out/CalendarDatePicker.html_bootstrap.dart:7:30)

これが私のビューコードです:

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    <title>CalendarDatePicker</title>
    <link rel="stylesheet" href="CalendarDatePicker.css">
  </head>
  <body>
    <element name="calendar" constructor="Calendar" extends="div">
      <template>
        <table>
          <tr>
            <th>Sun</th>
            <th>Mon</th>
            <th>Tue</th>
            <th>Wed</th>
            <th>Thu</th>
            <th>Fri</th>
            <th>Sat</th>
          </tr>
        </table>
      </template>
    </element>
    <div is="calendar"></div>
    <script type="application/dart" src="CalendarDatePicker.dart"></script>
    <script type="text/javascript" src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script>
  </body>
</html>

そして、これが私のメインスクリプトです。

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


void main() {

}

class Calendar extends WebComponent
{

}

次の行の自動生成されたコードで失敗しています:

new Calendar.forElement(__e0)
  ..created_autogenerated() //Exception: No such method: 'Calendar.forElement'
  ..created()
  ..composeChildren();
4

2 に答える 2

4

<element> nameで始まるように変更する必要がありx-ます:

<element name="x-calendar" constructor="Calendar" extends="div">

および<div is="calendar"></div>to:

<x-calendar></x-calendar>

またはis=、必要に応じて構文を使用できます。

これらは推奨される変更ですが、問題を解決するものではありません。これが機能する方法は

class Calendar extends WebComponent {}

タグ内<element>で(の兄弟として<template>)それ自体の内部に入りました。<script>

もう1つの方法は、コンポーネントコードを別のファイルに分離し、正しい構文を使用して明示的にインポートすることです。このようなもの:

<link rel="components" href="calendar_component.html">

そこで、アプリを4つのファイルに分割しました。calendarPicker.html、メインのhtmlファイルは次のようになります。

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    <title>CalendarDatePicker</title>
    <link rel="stylesheet" href="calendarDatePicker.css">
    <link rel="components" href="calendar_component.html">
  </head>
  <body>
    <x-calendar></x-calendar>

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

calendarDatePicker.dart非常に最小限です:

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

void main() {}

コンポーネントコード(calendar_component.dart)には次のコードがあります。

<!DOCTYPE html>
<html>
  <body>
    <element name="x-calendar" constructor="CalendarComponent" extends="div">
      <template>
        <table>
          <tr>
            <th>Sun</th>
            <th>Mon</th>
            <th>Tue</th>
            <th>Wed</th>
            <th>Thu</th>
            <th>Fri</th>
            <th>Sat</th>
          </tr>
        </table>
      </template>
      <script type="application/dart" src="calendar_component.dart"></script>
    </element>
  </body>
</html>

また、付随するdartファイル(calendar_component.dart)には、コンポーネントクラスが含まれています。

import 'package:web_ui/web_ui.dart';

class CalendarComponent extends WebComponent {}

お役に立てれば。提供されたコードを使用してアプリをビルドし、エラーを複製しました。次に、ここに示すコードで再構築しました。エラーなしで実行されます。

于 2013-01-07T21:23:05.920 に答える
2

Shailenが言ったように、タグにはカレンダータイプを定義するタグ(おそらくsrc =属性を持つ)が<element>含まれている必要があります。<script>

詳細はこちら: http ://www.dartlang.org/articles/dart-web-components/#component-declaration

noSuchMethodエラーが発生しないようにするため、バグhttps://github.com/dart-lang/web-ui/issues/297も提出しました:)

于 2013-01-08T00:52:41.190 に答える