我喜欢建立一个视频演示网站与dotvvm。当没有发生任何事情时,它必须在每次从列表中创建新视频时启动。使用bootstrap/MediaObject,我找不到事件'video ready playing‘,所以我们可以开始下一个视频。用Dotvvm解决这个问题的最好方法是什么,我不想为了这个回到angular。
Bas
更新:目前我使用的是html5标签,是不是还有一个dotvvm组件?示例:
<dot:Content ContentPlaceHolderID="ContentTemplate">
<div class="page">
<video ID="video1" width="320" height="240" autoplay>
<source src="/Style/video/video1.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<button onclick="playPause()">Play/Pause</button>
</div>
<script>
var myVideo = document.getElementById("video1");
function playPause() {
if (myVideo.paused)
myVideo.play();
else
myVideo.pause();
}
myVideo.addEventListener("ended", function () {
//get next video from viewmodel, (not hard coded)
var nextVideo = "/Style/video/video2.mp4"
myVideo.setAttribute("src", nextVideo)
//load
myVideo.load();
// switch of sound
myVideo.muted = true;
// play
myVideo.play();
}, true);
</script>
我们可以从viewModel获取nextVideo吗?我们如何做到这一点?
发布于 2018-08-21 21:40:07
1)设置javascript变量
你可以这样设置-例如。按带有命令的按钮
MyView.dothtml
...
<dot:button Click="{command: SetNextVideo()}" Text="Set next video" />
...MyViewModel.cs
....
IDotvvmRequestContext _requestContext;
...
public void SetNextVideo()
{
//_requestContext.ResourceManager.AddStartupScript("alert('my javascript after command');");
_requestContext.ResourceManager.AddStartupScript("nextVideo = ...... ");
}2.获取视图中Viewmodel属性的当前值
或者你可以在视图模型中声明字符串属性,在你的javascript中,你可以像这样通过knockout调用获得当前值:
视图模型
public string MyFoo {get;set;} = "bar";查看:
<script>
....
alert( ko.toJS(dotvvm.viewModels.root.viewModel.MyFoo) );
</script>这取决于你的脚本你真正想要做什么:)
https://stackoverflow.com/questions/45238976
复制相似问题