首页 > 解决方案 > 我们如何使用颤振中的 odoo_api 解析从 odoo 获取的结果?

问题描述

我使用了 odoo_api v1.0.2 包来从 odoo 中获取所有记录。

final domain = [
          ["sale_ok", "!=", false]
        ];
        var fields = ["name", "list_price"];
        client
            .searchRead("product.template", domain, fields)
            .then((OdooResponse result) {
          if (!result.hasError()) {
            print("Succesful");
            final data = result.getResult();
            print("Total: ${data['length']}");
            final records = ("${data["records"]}");
            print(records);
          } else {
            print(result.getError());
          }
        });

我想从 odoo 的产品列表中获取个人记录,并将其显示为我的颤振应用程序中的产品。

标签: flutterodoo

解决方案


创建一个模型,如:

class ItemModel {
  final int id;
  final String type;
  final int time;
  final String text;
  final bool dead;

  ItemModel.fromJson(Map<String, dynamic> parsedJson)
      : id = parsedJson['id'],
        type = parsedJson['type'],
        time = parsedJson['time'],
        text = parsedJson['text'],
        dead = parsedJson['dead'];

  Map<String, dynamic> toMap() {
    return <String, dynamic>{
      "id": id,
      "type": type,
      "time": time,
      "text": text,
      "dead": dead,
    };
  }
}

并使用喜欢 ->

final item = ItemModel.fromJson(parsedJson);

推荐阅读