Howto hook into 'PageLoaded' observer in SilverStripe 3?

允我心安 提交于 2019-12-13 01:29:19

问题


I need to execute a jQuery function after a page loaded. The docs told me that it would be possible to hook into the 'PageLoaded' observer.

So I tried it like shown there. I put this function

Behaviour.register({
    '#Form_ItemEditForm' : {
        initialize : function() {
            this.observeMethod('PageLoaded', this.pageLoaded);
            this.observeMethod('BeforeSave', this.beforeSave);
            this.pageLoaded(); // call pageload initially too.
        },
        pageLoaded : function() {
            alert("You loaded a page");
        },
        beforeSave: function() {
            alert("You clicked save");
        }
    }
});

into my cms.js which get's loaded in the backend. I tried it inside and outside (function($) { .. code ..}(jQuery)); and also inside the doucment.ready function inside the first function.

I always receive the same error in my console Uncaught ReferenceError: Behaviour is not defined. Where is my mystake?


回答1:


I believe you may have been looking at docs for 2.4, not 3.x

Version 3 and up are built using jQuery.entwine, where this from memory is old Prototype plugin stuff from 2.4, meaning of course that Behaviour is not defined, just as the error says.

The docs have recently been updated, so perhaps visit again, you might learn something new & much more helpful :)



来源:https://stackoverflow.com/questions/27609635/howto-hook-into-pageloaded-observer-in-silverstripe-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!