我在嘗試覆蓋converse.js核心功能時遇到問題。以下示例:https://conversejs.org/docs/html/development.html#writing-a-converse-js-plugin和https://conversejs.org/docs/html/quickstart.html。我的代碼如下所示:無法覆蓋converse.js核心功能
require(['converse'], function (converse) {
"use strict";
converse.plugins.add('pluginName', {
overrides: {
onConnected: function() {
this._super.onConnected();
},
ChatBoxView: {
showMessage: function (attrs) {
this._super.showMessage(attrs);
}
}
}
});
converse.initialize({
bosh_service_url: 'http://myurl.com/http-bind/',
i18n: locales.en,
show_controlbox_by_default: true,
roster_groups: true,
keepalive: true,
jid: '[email protected]',
message_carbons: true,
play_sounds: true,
anonymous: false,
allow_logout: false,
authentication: 'prebind',
prebind_url: '/prebind',
auto_list_rooms: true
});
});
此代碼部分工作。聊天顯示,它連接(this._super.onConnected();工作正常),但當我想顯示消息(ChatBoxView.showMessage函數)時出現錯誤。錯誤訊息是:TypeError:This。$ content is undefined。
如何「定義」ChatBoxView這種方法?
謝謝,JC品牌。它的工作就像一個魅力:) – Dusan
只是說,'任何'this._super'方法將失敗更長的繼承鏈 – Bergi
不,它實際上不會失敗。在master中的最新代碼中,有一個包裝器方法,它在調用override方法之前及時地設置適當的_super方法。所以,如果你有兩個覆蓋同一個方法的方法,它們都會被調用,最近的override方法被稱爲first方法,它的super方法將是另一個override方法,然後這個方法將原方法作爲它的超級方法。 –