view xml 中的 button 調用web用戶端事件

來源:互聯網
上載者:User

標籤:style   blog   color   使用   檔案   art   

最近寫一個模組 需要 在用戶端幹點事.
按常規的方法, 應該是寫個 用戶端模組. 在 用戶端 init, start, render 去渲染個按鈕出來幹事.暫時還不太理解WEB模組如何很好地同伺服器端通訊.
所以, 還是使用傳統的OE server 模組來幹這事.
OE 提供 ir.actions.client (用戶端事件) 來讓服務端與 用戶端進行事件互動.
所以, 只需要在 view xml 中. 添加個 button 並調用服務端事件, 然後 服務端返回一個 ir.actions.client 事件給用戶端即可. 不知道哪位大大有更好的辦法

<button name="act_start" type="object" string="Start"/>

然後 在對象中定義該對象 act_start  方法

def act_start(self, cr, uid, ids, context=None):        context={}        context["key"]="value"                        ret = {            ‘type‘: ‘ir.actions.client‘,            ‘tag‘: ‘lcd_video.btnPerview‘,            ‘context‘:context,        }        return ret

然後 在 模組JS檔案中, 去定義JS部分的對象

 

instance.my_sample.btn_start = function(parent, action){        var self = this;        //id        action.context.active_id        //ids        action.context.active_ids        //_name        action.context.active_model        // 更多參數 請查看相關文檔 或 用js調試 自行發掘        alert(‘test‘);        // and do something...        return false;    };
這時候. 不出異常. 點擊 按鈕即可調用 btn_start 方法了...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.