跳至内容
菜单
此问题已终结
2 回复
2949 查看

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
10161
0
11月 23
1475
0
1月 23
1950
1
8月 22
2807
0
6月 22
4268