2014-06-06 45 views
1

我找不到任何與kendo中knockout的「with」綁定類似的東西。Kendoui相當於淘汰賽的?

本質上我想能夠設置我的html的特定區域的上下文,以便我不必繼續引用我的observable的子屬性。

從ko文檔。

<h1 data-bind="text: city"> </h1> 
<p data-bind="with: coords"> 
    Latitude: <span data-bind="text: latitude"> </span>, 
    Longitude: <span data-bind="text: longitude"> </span> 
</p> 

而在劍道我不得不去

<h1 data-bind="text: city"> </h1> 
<p> 
    Latitude: <span data-bind="text: coords.latitude"> </span>, 
    Longitude: <span data-bind="text: coords.longitude"> </span> 
</p> 

回答

1

沒有了with劍道結合的任何直接等同。

作爲一種變通方法,您可以使用source binding是喜歡簡單的template在KO結合:

<h1 data-bind="text: city"> </h1> 
<p data-template="template" data-bind="source: coords"> 
    <script id="template" type="text/x-kendo-template"> 
     Latitude: <span data-bind="text: latitude"> </span>, 
     Longitude: <span data-bind="text: longitude"> </span> 
    </script> 
</p> 
+0

你真的不應該把模板本身引用它的元素中。 – Brett

+0

@Brett你有什麼具體的理由不去做?因爲官方文檔正是在http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/bindings/source#source-binding-to-non-array-value – nemesv

+0

上顯示了這種內聯模板使用情況。嗯,有趣。我一直在使用劍道3年,或者我完全不知道他們一直以這種方式記錄它,或者自從我上次引用該部分後他們更新了文檔。我立場糾正。 – Brett