flutter - 我们如何使用颤振中的 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 的产品列表中获取个人记录,并将其显示为我的颤振应用程序中的产品。
解决方案
创建一个模型,如:
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);
推荐阅读
- http - gunicorn - 禁用 HTTP OPTION 方法
- reactjs - React 功能组件 - 使用获取的数据时,得到的错误数据不足
- java - Tabula Py 在 Windows 中窃取焦点
- flutter - Flutter 通过 API 登录
- javascript - 无法从 github 安装 ot.js 库
- php - Laravel 8: InvalidArgumentException: Auth guard [admin] 未定义
- ansible - 在 hosts.yaml 文件中创建的分组中执行 playbook
- kuzzle - Kuzzle 自行关闭
- javascript - 在 Web 开发中排列按钮 div 的正确方法
- go - 在 geth 1.9.25v 中选择案例选择