【问题标题】:reciving JSON data in my odoo controller在我的 odoo 控制器中接收 JSON 数据
【发布时间】:2018-02-27 22:47:02
【问题描述】:

我使用 Ext.Ajax.request 将数据从 extJS 文件发送到我的 odoo 控制器,如下所示:

Ext.Ajax.request({
    url : '/serviceAP/fun',
    headers :{
         'Content-Type' : 'application/json'
    },
    method : 'POST',
    jsonData : {"params":
          {"cat" : "cat4",
           "date" : "02/11/2015",
           "notes" : "this notes 4"}
         }
 })

控制器是这样的:

@http.route('/serviceAP/fun', type="json", auth='public', website=True)

def func_test(self,**args):
    http.request.env['sap.orders'].create({"cat": args['cat'], "order_date": args['date'],
                                          "notes": args['notes']})

    return None

没有任何问题,可以正常使用 但是现在我想添加许多参数(cat5,cat6,...,catn)所以我需要使用一个 JS 数组我不知道如何处理它我尝试了很多东西但没有结果,因为这种方法仅适用于一个 json 元组 我想知道如何在两侧odoo(odoo控制器/js返回)中处理它

【问题讨论】:

标签: javascript python json extjs odoo


【解决方案1】:

我找到了 要制作它,我们应该创建一个这样的字典:

val = {}
val[0]={
 "cat": "cat4",
 "date": "02/11/2015",
 "notes": "this notes 4"
};
val[1]={
  "cat": "cat5",
  "date": "02/11/2015",
  "notes": "this notes 5"
};

在我们应该使用 params 键将其插入到 jsonData 之后

jsonData : {"params":val}

我们直接在控制器中使用它:

i=0
while i < len(args):
   http.request.env['sap.orders'].create({"cat": args[str(i)]['cat'],  "order_date": args[str(i)]['date'],"notes": args[str(i)]['notes']})
   i = i+1

希望对你有帮助,谢谢:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2018-09-25
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多