繁体   English   中英

JavaScript:如何将变量传递给webservice的onResult函数?

[英]JavaScript: How to pass variable to webservice onResult function?

如果已经问过了,请原谅我。 我不确定要使用什么关键词来查找这个问题。 在我的代码中,我进行了Web服务调用,并将其结果传递给函数。

stockService.GetVideoGet(P.Guid.substring(1), ResponceType).onResult = LoadVideoPlayer;

在功能LoadVideoPlayer中,我浏览结果并构建一个自定义视频播放器。 如果该视频不存在,那么我会提醒您该视频已被禁用。 我想做的是.onResult传递函数LoadVideoPlayer函数变量P.Guid,以便如果视频不存在,我可以使用它删除播放器代码。

这是我到目前为止所拥有的。

    LoadVideoPlayer = function (result) {
    if (result.StatusMessage.toString() === "Success") {
        //Build Player using the result information. In the result information is the player ID and I use that ID to refrence the div on the htmlplage to know were the player should be built.
    } else {
        alert(result.StatusMessage.toString());
        //If the player is disabled I dont get a player ID so my player div doesnt know what to do. I am unable to change the webservice results. So I want to try to pass in the P.Guid and use that as the player ID.
    }}

是否可以做这样的事情

        LoadVideoPlayer = function (result, P) {
    if (result.StatusMessage.toString() === "Success") {
        //Build Player using the result information. In the result information is the player ID and I use that ID to refrence the div on the htmlplage to know were the player should be built.
    } else {
        alert(result.StatusMessage.toString());
        $('#'+P.Guid).innerHTML = 'This player has been disabled.'
    }}

弄清楚了。 我必须使用绑定并切换我的函数变量。

stockService.GetVideoGet(P.Guid.substring(1), ResponceType).onResult = LoadVideoPlayer.bind(this, P.Guid);

LoadVideoPlayer = function (PG, result) {
if (result.StatusMessage.toString() === "Success") {
    //Build Player using the result.
} else {
    alert(result.StatusMessage.toString());
    alert(PG);
}}

暂无
暂无

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

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