开发者

JavascriptMVC custom events

开发者 https://www.devze.com 2023-03-19 03:56 出处:网络
I have recently been experimenting with the Core parts of Javascript MVC, well the MC bit for the time being.

I have recently been experimenting with the Core parts of Javascript MVC, well the MC bit for the time being.

When i fire a custom event from a model eg. this.publish('initialised'); the documentation states that 'The model's short name will be automatically prefixed.'. However whenever this event is published it seems to use _shortName property which is always 'model', not the name of the class firing the event.

so i always have an event model.initialised instead of, for example, Data.initialised with Data being the model name and this is what i want.

I can see in the source code where this happens. In the static methods of the jQuery.Model definition there is this:

publish: function( event, data ) {          
    if ( window.OpenAjax ) {
        OpenAjax.hub.publish(this._shortName + "." + event, data);
    }
},

I could remove the underscore above and it does what i want (and what it should do?) as this.shortName contains the correct name for the model but its surely not the way to go.

My app seemed to be publishing events correctly before i upgraded jquery from 1.4.x to 1.5.x (i have no choice in which jquery version i use being part of a large organisation) and as far as i can gather openAjax isnt available to 1.4.x. So i am thinking due to this change, the mechanism javascript MVC uses to pub/sub is different. Any ideas what i am doing wrong? Can post more specific code if nec开发者_StackOverflow社区cesary.

any help greatly appreciated

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号