简体   繁体   English

如何在ajax加载的页面中使用MVC的功能?

[英]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.

相关问题 如何在加载页面之前提交ajax请求 - How do i submit an ajax request before the page is loaded 如何使用AJAX加载的内容中的javascript? - How do I use javascript from content loaded with AJAX? Ajax已加载页面的一部分-如何使已加载内容中的链接正常工作? - Ajax loaded part of a page - how do I make links in the loaded content work? 如何从同一页面上的Ajax加载内容访问javascript函数? - How can i access javascript functions from ajax loaded content on the same page? 如何在没有服务的情况下将mjc4与ajax一起使用? - How do I use ajax with mvc4 without a service? 我有一个使用ajax调用在另一个页面的div标签中加载的html页面,我想在加载的页面上触发javascript函数吗? - I have a html page that loaded in div tag in another page using ajax call I want to trigger javascript functions on loaded page? 加载了ajax的页面的某些部分无法使用功能 - parts of page loaded with ajax dont work with functions 使用Ajax将内容加载到div中...如何将加载新页面的div定位到同一div? - Loading content into div with Ajax … How do I target the same div with the new page loaded? 页面加载后如何加载外部js文件并使用同一js中的函数 - how do i load an external js file after the page has loaded AND use a function from that same js 使用JonintJS,如何在页面加载后在画布上绘制图形? - Use JonintJS,How do I draw a graph on the canvas after the page is loaded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM