Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 索引器错误:元组索引超出范围。奥多14_Javascript_Python_Xml_Odoo - Fatal编程技术网

Javascript 索引器错误:元组索引超出范围。奥多14

Javascript 索引器错误:元组索引超出范围。奥多14,javascript,python,xml,odoo,Javascript,Python,Xml,Odoo,在我的代码中,我得到了以下错误: File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception raise exception.with_traceback(None) from new_cause IndexError: tuple index out of range 打印VAL['partner_id']时,我得到:[(4,3)] 这是我的密码,请问怎么了

在我的代码中,我得到了以下错误:

File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception
    raise exception.with_traceback(None) from new_cause
IndexError: tuple index out of range
打印VAL['partner_id']时,我得到:[(4,3)] 这是我的密码,请问怎么了

class CalendarEvent(models.Model):
    _inherit = 'calendar.event'

    present_ids = fields.Many2many('res.partner', 'calendar_event_present_ids', 'calendar_id', 'present_id', string='Presents')
    minutes = fields.Html(string='Minutes')

    @api.model
    def create(self, vals):
        if vals.get('partner_ids', False):
            _logger.info("%s", vals['partner_ids'])
            vals.update({'present_ids': [(6, 0, vals.get('partner_ids')[0][2])]})
        return super(CalendarEvent, self).create(vals)
试试这个:

list_data = vals.get('partner_ids')[0][2]
blank_list = [ls for ls in list_data] # you'll get the list
也可以使用循环创建列表

blank_list = []
for l in list_data:
    blank_list.append(l)
# then use [(6, _, ids)]
vals.update({'present_ids': [(6, 0, blank_list)]})

元组索引从0开始,因此如果元组只有2个元素,则唯一有效的正索引是0和1。使用2会产生一个错误,请问我如何解决它?尝试使用[0][1]时,我遇到以下错误:TypeError:“int”对象不可用iterable@Cerestry打印
vals.get('partner_id')
我得到:[(4,3)],@ceresw当使用
[(6,id)]
时,
ids应该是一个整数列表。