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

Hi,


I 'm building a custom view and I want to redirect to menu item when a user click on an div element. 


I tried something like that in my template

<a t-attf-href="#menu_id=MENU_ID">...</a>

 

And it works, but it breaks the browser history.


Maybe there is way to do this from the js but I can't something that match my need


Any clue ?


Regards











アバター
破棄
最善の回答

try this way:
template>

div id="myDivElement">Click here to go to the menu item

/template>


JS:
odoo.define('my_module.my_view', function (require) {

'use strict';


var core = require('web.core');


$(document).ready(function () {

// Get the menu ID you want to redirect to

var menuID = YOUR_MENU_ITEM_ID;


// Add a click event listener to the div element

$('#myDivElement').on('click', function () {

// Redirect to the specified menu item

core.bus.trigger('menu_item_clicked', menuID);

});

});


});


Replace YOUR_MENU_ITEM_ID with the actual ID of the menu item you want to redirect to. When the user clicks on the div element, the event listener will be triggered, and it will call the core.bus.trigger method with the 'menu_item_clicked' event, which will navigate to the specified menu item without breaking the browser history.

アバター
破棄
最善の回答

Hi,

You can try this code

<a t-attf-href="/web#id={{object.id}}&amp;cids={{object.env.user.id}}&amp;menu_id={{object.env.ref('module_name.menuitem_id').id}}&amp;action={{object.env.ref('module_name.action_id').id}}&amp;model=model.name&amp;view_type=form" style="background-color:#875a7b;padding:8px 16px 8px 16px;text-decoration:none;color:#fff;border-radius:5px;font-size:13px">Click Here</a>

this is the example for adding button click and the corresponding actions
  

Hope it helps

アバター
破棄
関連投稿 返信 ビュー 活動
2
4月 16
10190
0
11月 23
1510
0
1月 23
1978
1
8月 22
2854
0
6月 22
4287