コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
5103 ビュー

Dear All,

I am getting an error when load a function. The intial page is loading without issue, after clicking the card-body, i am getting result in console.log(FloorId); 

My problem is when i pass the

this.state.tokenFloorId = FloorId; inside async selectFloor(data),
i am getting "Error fetching floor list: TypeError: this is undefined".



here is my function:

/** @odoo-module */

import { registry } from '@web/core/registry';
import { Component, useState, onMounted,onWillStart } from "@odoo/owl";
import rpc from 'web.rpc';

export class CallingToken extends Component {
setup() {
super.setup();
this.state = useState({
tokenTypeId: null,
tokenFloorId: null,
departmentId: null,
});
onMounted(this.fetchInitialData.bind(this));
//onWillStart(this.onWillStart);
}

async fetchInitialData() {
try {
const initialTokenTypeId = await rpc.query({
model: "token.issue.station.wizard",
method: 'fetch_token_type',
args: [1],
});
this.state.tokenTypeId = initialTokenTypeId;
} catch (error) {
console.error("Error fetching initial tokenTypeId:", error);
}
}

async selectFloor(data) {
try {
const FloorId = await rpc.query({
model: "token.issue.station.wizard",
method: 'fetch_floor_type',
args: [1, data],
});
console.log(FloorId);
this.state.tokenFloorId = FloorId;
} catch (error) {
console.error("Error fetching floor list:", error);
}
}
}

CallingToken.template = 'queue_management.CallingToken';
registry.category('actions').add('queue_management.action_call_token_js', CallingToken);

My template is :

t-name="queue_management.CallingToken" owl="1">
class="container-fluid bg-gradient">
class="row">

Token Issuing Page


class="row justify-content-center" name="token_table">
t-if="state.tokenTypeId">

Stations here
class="col-lg-6 col-md-8 col-sm-10 col-12 text-center">
t-foreach="state.tokenTypeId" t-as="data" t-key="data.rec_id">
class="tile mb-3">
class="card" t-on-click="() => selectFloor(data.rec_id)">
class="card-body" t-att-code="data.rec_id">
class="card-title">t-esc="data.token_type_name"/>

class="card-text">
t-esc="data.token_type_name"/>












t-if="state.tokenFloorId">

Select Floor
class="col-lg-6 col-md-8 col-sm-10 col-12 text-center">
t-foreach="state.tokenFloorId" t-as="floor" t-key="floor.rec_id">
class="card">
class="card-body">
class="card-title">t-esc="floor.floor_name"/>

class="card-text">
t-esc="floor.floor_name"/>








アバター
破棄
最善の回答

Hi,

In your case 'this' is not properly bound to your class's instance. it seems that 'this' is not correctly bound within the 'selectFloor' function. To ensure 'this' is correctly bound, you can use an arrow function for the 'selectFloor' method. You make sure that your class instance is correctly bound to 'this,'
import { registry } from '@web/core/registry';
import { Component, useState, onMounted } from "@odoo/owl";
import rpc from 'web.rpc';

export class CallingToken extends Component {
    setup() {
        super.setup();
        this.state = useState({
            tokenTypeId: null,
            tokenFloorId: null,
            departmentId: null,
        });
        onMounted(this.fetchInitialData.bind(this));
    }

    async fetchInitialData() {
        try {
            const initialTokenTypeId = await rpc.query({
                model: "token.issue.station.wizard",
                method: 'fetch_token_type',
                args: [1],
            });
            this.state.tokenTypeId = initialTokenTypeId;
        } catch (error) {
            console.error("Error fetching initial tokenTypeId:", error);
        }
    }

    selectFloor = async (data) => { // Use an arrow function
        try {
            const FloorId = await rpc.query({
                model: "token.issue.station.wizard",
                method: 'fetch_floor_type',
                args: [1, data],
            });
            console.log(FloorId);
            this.state.tokenFloorId = FloorId;
        } catch (error) {
            console.error("Error fetching floor list:", error);
        }
    }
}

CallingToken.template = 'queue_management.CallingToken';
registry.category('actions').add('queue_management.action_call_token_js', CallingToken);


Hope it helps

アバター
破棄
著作者

Thank you.. working...

関連投稿 返信 ビュー 活動
1
12月 23
1673
1
10月 23
3952
0
8月 23
194
1
2月 22
2988
0
8月 18
5945