Dart js 与 D3 互操作 [英] Dart js interop with D3

查看:33
本文介绍了Dart js 与 D3 互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 D3 与 dart 集成:到目前为止,我的代码如下:

I am trying to integrate D3 with dart: My code to this point is as follows:

import 'dart:html';
import 'package:js/js.dart' as js;

void main() {
   js.scoped(() {
     var dee3 = js.context.d3; 
     var dataset = js.array([ 5, 10, 15, 20, 25 ]);
     dee3.select("body").selectAll("p")
    .data(dataset)
    .enter()
    .append("p")
    .text(function(d) { return d; });

  });

每当我在 dartium 中运行它时,我都会收到以下异常:例外:函数必须先转换为回调,然后才能序列化.如何将匿名函数(d)转换为回调?

Whenever I run this in dartium I get the following exception: Exception: A function must be converted to a Callback before it can be serialized. How can I convert the anonymous function(d) to a callback?

推荐答案

As package:js > 0.2.0 Callbackjs.scoped 不再需要.

As package:js > 0.2.0 Callback and js.scoped are no longer needed.

import 'dart:html';
import 'package:js/js.dart' as js;

void main() {
  var dee3 = js.context.d3; 
  var dataset = js.array([ 5, 10, 15, 20, 25 ]);
  dee3.select("body").selectAll("p")
    .data(dataset)
    .enter()
    .append("p")
    .text((d, i, context) => d);
}

这篇关于Dart js 与 D3 互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆