콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4592 화면

Hello everyone, I am developing a small Todo List app on Odoo 17 to learn Owl. Everything was progressing smoothly until I attempted to dynamically fetch and display data using orm with useService. I encountered the following error:


Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'orm' in undefined


I have extensively tried to resolve the issue by consulting the Owl and Odoo documentation, as well as searching for solutions online, but without success. The code adheres to the documentation, and I am uncertain about the source of this error.


Steps to Reproduce:

1. clone this repo somewhere

2. start odoo with this repo in the addons-path, on a recent version (odoo 17)

3. install the odoo_owl_app addon

4. go to the /owl-app route to see the result.


Code:

The root.js file contains the following codes:


/** @odoo-module */

import { Component, useState, useSubEnv, onWillStart } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";


import { WebsiteLayout } from "./layouts/website/layout"
import { TodoForm } from "./components/todo_form/todo_form";
import { Todos } from "./components/todos/todos";

export class Root extends Component {
    static template = "odoo_owl_app.root";
    static components = { WebsiteLayout, TodoForm, Todos };
    static props = {};

    setup() {
        this.todos = useState([]);
        this.orm = useService("orm");
        this.model = 'odoo_owl_app.todo';

        this.handleChangeState = (event) => {
            const id = event.target.value;
            const index = this.todos.findIndex(todo => todo.id === parseInt(id))
            this.todos[index].is_completed = !this.todos[index].is_completed
        };

        this.handleEdit = (id, title) => {
            const index = this.todos.findIndex(todo => todo.id === parseInt(id))
            this.todos[index].title = title
        };

        this.handleRemove = (id) => {
            console.log('remove', id)
            const index = this.todos.findIndex(todo => todo.id === parseInt(id))
            this.todos.splice(index, 1);
        };

        this.onAdd = (title) => {
            const todo = {
                userId: 1,
                id: new Date().getTime(),
                title,
                is_completed: false
            }
            this.todos.push(todo)
        };
    }
}



When this code  this.orm = useService("orm"); is added to the setup, the following error is issued:



Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'orm' in undefined



Screenshot:

![Screenshot from 2023-12-01 18-58-50](https://github.com/odoo/owl/assets/42430858/49b653a0-67c0-4c8f-b254-604262788b9f)



Additional Information:

- Odoo Version: 17


Projects:

-  this repo


I appreciate any assistance in resolving this issue and gaining a better understanding of using Owl with Odoo.

아바타
취소
작성자 베스트 답변

The problem was that I hadn't started the service, so useService couldn't work.


To solve this problem, I used mountComponent instead of mount in the app .js file.


More information at https://www.odoo.com/documentation/master/developer/howtos/standalone_owl_application.html

아바타
취소
관련 게시물 답글 화면 활동
1
9월 23
5128
1
8월 23
411
1
6월 24
3303
1
12월 23
1686
1
10월 23
3958