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

Can I inherit a defined "ir.ui.view" by its id in JavaScript?

For example, given the following view, Can I modify the target_field of module.model_tree_view in javascript code, like if (model.condition){ $([name="target_field"]).hide()}. If so can you also provide some example codes please, Thank you.

<record model="ir.ui.view" id="module.model_tree_view">
<field name="name">Model List View</field>
<field name="model">module.model</field>
<field name="arch" type="xml">
<tree>
            <field name="target_field"/>
</tree>
</field>
</record>

아바타
취소
작성자

attrs="{'invisible': [('state','=','close')]}" can only set read, edit and invisible. In some use cases, we may want to change the style of a specific element not just hide or show but more fancy way, that is why I ask for the way to do it in javascript instead of XML or python code.

ok got it

작성자

The question is exactly how to modify the javascript widget to a specific view id only.

작성자 베스트 답변

Instead of modifying the view by its id, we can extend the view widget and add the new view to the view registry. Then, we can add the attribute, js_class to the view to apply the new changes. In this case, only your view with js_class name will have the extended features in it, other normal kanban (without the js_class) will remain the same as before.

In your js file,

let view_registry = require('web.view_registry');
let KanbanView = require('web.KanbanView');
let myKanBanView = KanbanView.extend(...)
view_registry.add('my_custom_kanban', myKanBanView);

In your xml file,

<kanban js_class="my_custom_kanban">...<kanban/>

아바타
취소
베스트 답변

can you use something like,

attrs="{'invisible': 
[('state','=','close')]}"
아바타
취소
베스트 답변

you could not apply jquery directly on fields because of the client architecture you define view in XML and client view rendering engine converts it to HTML which understood by the browser. 

On the top of it, the client has MVC architecture so data/model (your condition) and View (HTML element) are separated by the controller. 
but you can easily achieve your requirement by extending the javascript widget it has both data and view.

아바타
취소