mongodb - 导入mongo_dart程序包阻止显示文本

标签 mongodb dart

以下代码可以正常工作...只需在无序列表中显示一些JSON:

import 'dart:html';
import 'dart:convert';

main() {
 // Db db = new Db("mongodb://127.0.0.1/mongo_dart-showjson");
  querySelector("#sample_text_id")
      ..onClick.listen(showJSON);
}

void reverseText(MouseEvent event) {
  var text = querySelector("#sample_text_id").text;
  var buffer = new StringBuffer();
  for (int i = text.length - 1; i >= 0; i--) {
    buffer.write(text[i]);
  }
  querySelector("#sample_text_id").text = buffer.toString();
}

void showJSON(MouseEvent event) {
  var path = 'hcps.json';
  var hcpDisplay = querySelector('#json_length_id');
  HttpRequest.getString(path).then((String fileContents) {
    List<String> hcpList = JSON.decode(fileContents);
    for (int i = 0; i < hcpList.length; i++) {
      hcpDisplay.children.add(new LIElement()..text = hcpList[i].toString());
    }

  });
}

但是,当我为mongo-dart添加import语句时,虽然没有收到错误,但不显示JSON:

import 'dart:html';
import 'dart:convert';
import 'package:mongo_dart/mongo_dart.dart';

main() {
  Db db = new Db("mongodb://127.0.0.1/mongo_dart-showjson");
  querySelector("#sample_text_id")
      ..onClick.listen(showJSON);
}
...

mongo_dart软件包已作为依赖项添加到pubspec.yaml。

有没有人知道为什么导入mongo_dart包会导致json文本不显示,尽管没有错误?先感谢您。

最佳答案

如包装自述文件所述

mongo-dart is a server-side driver library for MongoDb implemented in pure Dart




它不能在客户端工作。主要原因是-浏览器没有真正的套接字来连接到mongodb,mysql,postgress等数据库。您可能会看一些带有RESTful API的数据库,例如CouchDB。或者您应该使用一些中间件,例如objectory

关于mongodb - 导入mongo_dart程序包阻止显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23740547/

相关文章:

mongodb - 无法运行 Mongo shell (Mac)

mongodb - Kubernetes MongoDB 自动缩放

flutter - 我应该发布有关参数变化的问题吗

dart - flutter : Sort widget according to a sorted list of values

svg - Dart SVG矩阵转换

mongodb - golang mongoDB 唯一索引在多个键时不起作用

javascript - 确保 "done()"被称为JS错误

javascript - Meteor,按 bool 值显示/排序值

flutter - 如何在具有 flutter 透明度的 png 上应用滤色器?

flutter : Keyboard without decimal point