dart - 如何在js-interop中访问绑定(bind)this?

标签 dart dart-js-interop

我正在尝试使用React来自 Dart 的库。

但是,我需要提供由 React 调用的各种函数,并将 this 绑定(bind)到某个 javascript 对象。我知道,我可以使用 js interop Callback 类向 javascript 代码提供 Dart 回调,但是我不知道如何在这些回调中访问 javascript this

能帮我查一下吗?

最佳答案

您必须在创建Callback时使用可选的命名参数withThis。这样,当调用 dart 函数时,javascript this 将被添加为第一个参数。像这样的东西:

var func = (jsThis, arg1) {
  // do the job with jsThis
};
new Callback.many(func, withThis: true);

关于dart - 如何在js-interop中访问绑定(bind)this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19422483/

相关文章:

angular-ui-router - 角 Dart : How to change partial parts of layout based on navigation?

dart - 使用 Dart :js to stream audio through the SoundCloud JavaScript API

dart - 如何与现有的 JS 对象进行互操作?

json - Flutter & SurveyKit - 如何将 SurveyResult 序列化为 JSON

dart - 通过 Javascript 函数传递 Polymer 数据绑定(bind)

json - 当响应是对象数组时,如何在抖动中解析JSON

json - 使用Dart将输入表单中的数据存储到JSON中

google-chrome-extension - 在 dart 中构建 chrome 扩展时出现 chrome.runtime.onConnect 问题

javascript - 从 Dart 代码调用匿名 Javascript 函数

javascript - JS 到 Dart 转换