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

问题描述 投票:1回答:1

如果已经提出要求,请原谅我。我不确定用什么关键词来查看这个问题。在我的代码中,我进行了一个webservice调用,并将其结果传递给一个函数。

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.'
    }}
javascript variables
1个回答
0
投票

弄清楚了。我不得不使用bind并切换我的函数变量。

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);
}}
© www.soinside.com 2019 - 2024. All rights reserved.