简体   繁体   English

从javascript文件调用视图javascript函数

[英]Call view javascript function from javascript file

I have a jquery template that is being loaded with values after the ajax call is done and not on the view load. 我有一个jquery模板,它在ajax调用完成后正在加载值,而不是在视图加载时加载。

on page load my javascript calls and function from a script.js file. 页面上从script.js文件加载我的JavaScript调用和函数。 i need that script.js file to call another function from the view. 我需要那个script.js文件从视图中调用另一个函数。 How would i call the listload function from the script.js 我如何从script.js调用listload函数

var limit = 5, dir = ' Desc', sort = 'Created', index = 0, autoscroll = false;
function getDataUrl(index, action) {

    return '/Team/Linking/ListItemLinks/@Model.ItemId/?type=@Model.ItemType';

}
function listload() {
    alert('test');

}

Corey, 科里

As per my understanding, you will invoke a function in a js file from a view and after that the js file will invokes another function residing in the same view. 根据我的理解,您将在一个视图中的js文件中调用一个函数,此后,该js文件将在同一视图中调用另一个函数。

I think you can achieve it (By theoritically) because, 我认为您可以实现(理论上),因为,

  1. When the page loads, it will clubs all the js. 页面加载时,它将合并所有js。
  2. Consider, if your js file points to a Master/layout page , when the inner page loads it will have the cumulative js (from page,outside js files and master/layout pages). 考虑一下,如果您的js文件指向母版/版面页面,那么在内页加载时,它将具有累积的js(来自页面,外部js文件和母版/版面页面)。 So you can call the function residing in the page from js (need to verify). 因此,您可以从js调用页面中的函数(需要验证)。

I think jQuery may have similar kind of stuffs, because we are calling jquery using an external file, but after that it calls the next line. 我认为jQuery可能有类似的内容,因为我们使用外部文件调用jquery,但此后它将调用下一行。

Another thing is to check with the callbacks and events in javascript. 另一件事是检查javascript中的回调和事件。 I am not expert in topic. 我不是主题专家。 You can check the following links, may be it helps you. 您可以检查以下链接,可能对您有帮助。 Create a custom callback in JavaScript http://blog.pengoworks.com/index.cfm/2012/1/12/Adding-custom-callbacks-to-existing-JavaScript-functions 在JavaScript中创建自定义回调 http://blog.pengoworks.com/index.cfm/2012/1/12/Adding-custom-callbacks-to-existing-JavaScript-functions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM