asp.net-core-mvc - Asp.NET core View 组件视图未触发 $(document).ready()
问题描述
我是 ASP.NET 核心的新手。我正在使用基于条件的视图组件在组件文件夹下加载不同的视图。
<div class="container" id="patientLayout">
@await Component.InvokeAsync("PatientView", new {model = Model})
</div>
public async Task<IViewComponentResult> InvokeAsync(PatientTabViewModel model)
{
switch (model.Id)
{
case 3:
PatientMessageViewModel msgModel=GetMessagesViewModel(model.PatientId);
return await Task.FromResult(View("_messages.cshtml", msgModel));
}
}
我有一个$(document).ready()
功能_Messages.cshtml
<script type="text/javascript">
$(document).ready(function () {
console.log('ready function fired');
}
});
</script>
问题:这个准备好的函数只是第一次被触发,但下一次它不会被触发,但断点每次都会在案例 3 处被击中。
您能否为此提供一些信息/解决方案?
解决方案
仅当页面文档对象模型 (DOM) 准备好执行 JavaScript 代码时,其中包含的代码$( document ).ready()
才会运行。$( window ).on( "load", function() { ... })
一旦整个页面(图像或 iframe)(而不仅仅是 DOM)准备就绪,其中包含的代码就会运行。参考: $( document ).ready()
推荐阅读
- python - 通过 Airflow 中的 PythonVirtualenvOperator 多次运行成功的数据流管道
- javascript - 如何使用 Javascript 创建 txt 文件并使用 txt 文件的内容创建一个 html 文件?
- php - 如何从谷歌驱动器获取视频文件的可播放链接
- javascript - 使用没有分区键规范的查询从 Cosmos 中删除文档
- php - 使用 php exec 运行 youtube-dl
- python - 如何指定要在 Python 脚本中更改的 xml 文件中的多个字符串?
- spring - 现有 API 的移动应用程序身份验证
- python - 使用带有列名和值的字典对 Pandas 数据帧进行一次性编码
- javascript - 从反应原生移动项目向本地 api 发送获取请求
- laravel - Laravel 和 Vue:我的布局刀片加载了我的组件看不到的脚本