2012-12-28 67 views
0

我有一個選擇控件,我有一個訂閱。當我不應用劍道風格時,控件按預期工作,訂閱代碼會觸發一次,並且不會在blur或任何其他原因下重新啓動。當我應用kendoDropDownList時,訂閱的行爲始終不穩定淘汰賽訂閱選擇射擊與KendoUI不一致

$("select").kendoDropDownList(); 

不規律的行爲是選擇一個值,訂閱觸發。單擊另一個控件,訂閱事件再次觸發並且值未定義,即使選擇控件顯示值未更改。隨後的選擇會按預期觸發訂閱。 使用kendo時,使用選擇控件上的向下/向上箭頭也不會觸發。

<select id="newExperienceFrequency" data-bind="value: frequency, options: $root.controls.frequencies, optionsText: 'name', optionsValue: 'id', optionsCaption: 'Select', event: { mouseover: mouseoverFrequency, mouseout: mouseoffFrequency }" class="select frequencyTip" title="foo"></select> 


    self.proficiency.subscribe(function() { 
     self.proficiencyId = self.proficiency(); 
     console.log('proficiency subscribed: ' + self.proficiency()); 
     my.setCounterHint($("#newExperienceFrequency").val(), self.proficiency()); 

     var tip = "Don't just list those skills your strongest in. It's just as important to add new skills you are aquiring!"; 
     var result = $.grep(my.ajaxData.member.Proficiencies, function (e) { return e.Id == self.proficiency(); }); 
     if (result.length == 0) { 
      // not found 
     } else if (result.length == 1) { 
      // access the foo property using result[0].foo 
      tip = result[0].Name + ':\nAutonomy: ' + result[0].Autonomy + '\nContext: ' + result[0].nContext + '\nKnowledge: ' + result[0].Knowledge + '\nWorkmanship: ' + result[0].Workmanship; 
     } else { 
      // multiple items found 
     } 
     $(".proficiencyTip").attr('title', tip).attr('alt', tip); 
     $(".proficiencyQuestionMark").fadeIn('slow'); 
    }); 

這是一個已知的問題,還是我只是做錯了什麼?我是否試圖通過Knockout使用Kendo來爲自己做更多的工作?如果我只是使用劍道並淘汰淘汰賽,這些問題是否會消失?

回答

0

我不與KendoUI熟悉,因爲我用的淘汰賽。但是如果我不得不猜測,劍道會引發一個改變的事件,而這個事件會導致淘汰賽比正常情況下的射門更多。

我會推薦給你的訂閱參數爲新值,而不是在訂閱指的self.proficiency()。然後,您可以檢查訂閱中是否定義了該值。

另外,我建議重新評估的方式,以避免在您的視圖模型做的jQuery。如果你必須執行jQuery使自定義動畫或新的綁定。您很可能可以將您的用戶界面綁定到虛擬機中的另一個屬性,並將您的視圖/虛擬機解耦。

例如所述的問號元件可以被結合到一個布爾觀察到。製作一個自定義綁定fadeVisible。我依稀記得那個文檔有一個樣本。它不難做出。 (提示:http://knockoutjs.com/examples/animatedTransitions.html

self.proficiency.subscribe(function(val) { 
    if (typeof(val) === 'undefined')) { 
     return; 
    } 
}); 
+0

優秀的觀察!我對Knockout(以及整個web 2.0)非常陌生,並會查看您的鏈接。事實證明,我找到了利用ryan niemeyer綁定Kendo的答案http://rniemeyer.github.com/knockout-kendo/web/DropDownList.html –