簡體   English   中英

訂閱事件不會每次都被調用

[英]Subscribe event not getting called everytime

我有搜索屏幕,當用戶導航到結果頁面時,結果頁面上有帶有值(分鍾,字符)的單選按鈕。

我已經在結果頁面上訂閱了單選按鈕單擊事件,每當用戶單擊單選按鈕訂閱功能時,都應該調用該事件。

現在的問題是:

1)當用戶第一次點擊搜索按鈕時,顯示結果。

2)用戶選擇“分鍾”單選按鈕,訂閱事件被調用並開始工作。

3)用戶選擇返回按鈕,並且用戶被重定向到搜索屏幕。

4)用戶點擊搜索按鈕,結果顯示。

5)用戶試圖單擊“字符”按鈕,沒有調用訂閱事件。

她的是我的代碼:

<div class="nmc-righttab" style="width: 60%">
    <div class="nmc-righttab" style="margin-left:20px">
        <label class="nmc-label" style="line-height:21px">@Res.Trends.DisplayResultBy</label>
    </div>
    <div class="nmc-righttab" style="width:250px">
        <div class="nmc-lefttab" style="margin-left:5px">
            <input type="radio" id="MinuRadio" name="GphInterval" value="2" data-bind="checked:GraphClick" />
        </div>
        <div class="nmc-righttab">
            <label class="nmc-label" for="MinuRadio" style="line-height:21px">@Res.Trends.Minutes</label>
        </div>
        <div class="nmc-lefttab" style="margin-left:5px">
            <input type="radio" id="CharRadio" name="GphInterval" value="3" data-bind="checked:GraphClick" />
        </div>
        <div class="nmc-righttab">
            <label class="nmc-label" for="CharRadio" style="line-height:21px">@Res.Trends.Characters</label>
        </div>
    </div></div>

JS代碼:

  this.GraphClick.subscribe(function (val) {
      model.showGraphResults(true);
      model.GraphIntervalSelected(val);
      searchSpeechGraphView(speechUsage);
  }, this)

與其將this參數作為參數傳遞給subscribe方法,不如將其與this對象綁定在一起。 像這樣

JS代碼:

this.GraphClick.subscribe(function (val) {
  model.showGraphResults(true);
  model.GraphIntervalSelected(val);
  searchSpeechGraphView(speechUsage);
}.bind(this));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM