[英]How do I use functions of the MVC in a page loaded by ajax?
My controller looks something like this: 我的控制器看起来像这样:
jQuery.extend({
Controller: function(model, view){
//-----VIEW-----//
var vlist = $.ViewListener({
clickItem : function(Item){
switch (Item) {
case 'File':
//do something
break;
default:
//do something else
}
}
});
view.addListener(vlist);
//-----MODEL-----//
var mlist = $.ModelListener({
gotContent : function(Item) {
switch (Item.type) {
case 'Download':
//do someting else
break;
default:
//do something else
}
//update view
}
});
model.addListener(mlist);
}
});
How do I use the clickItem function from a page that was not created by the MVC? 如何使用非MVC创建的页面中的clickItem函数?
I have tried view.clickItem and many other ways however nothing is defined because it is all in private functions. 我尝试过view.clickItem和许多其他方式,但是没有定义任何东西,因为它们全部在私有函数中。
I load the MVC like this: 我这样加载MVC:
$(function(){
var model = new $.Model();
var view = new $.View($("#framework"));
var controller = new $.Controller(model, view);
view.init();
});
Basically I have link that I would like to act the same way as the clickItem function. 基本上,我具有与clickItem函数相同的链接。
Was able to get around this by using jQuery's .live() method. 能够通过使用jQuery的.live()方法解决此问题。 On the ajax success callback I ran a jQuery .live() method to attach an onclick event to the element that calls the clickItem() function.
在ajax成功回调中,我运行了jQuery .live()方法,将onclick事件附加到调用clickItem()函数的元素上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.