All Components

MVVM / Custom binding

One Big Orange Spot.

Slide Binding

View source code:

<div id="target" data-bind="slide: slideValue">
    One Big Orange Spot.
</div>
<label>
    Toggle: <input type="checkbox" data-bind="checked: slideValue" />
</label>
        

Custom binder source code:

kendo.data.binders.slide = kendo.data.Binder.extend( {
    refresh: function() {
        var value = this.bindings["slide"].get();

        if (value) {
            $(this.element).slideDown();
        } else {
            $(this.element).slideUp();
        }
    }
});
        

View model source code:

var viewModel = kendo.observable({
    slideValue: true
});

kendo.bind($("#example"), viewModel);
        

HTML5/JavaScript 源码

<!DOCTYPE html>
<html>
 <head> 
  <title>Custom binding</title> 
  <meta charset="utf-8"> 
  <link href="../content/shared/styles/examples-offline.css" rel="stylesheet"> 
  <link href="../../styles/kendo.common.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.rtl.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.default.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.default.min.css" rel="stylesheet"> 
  <script src="../../js/jquery.min.js"></script> 
  <script src="../../js/kendo.all.min.js"></script> 
  <script src="../content/shared/js/console.js"></script> 
  <script>
        
    </script> 
 </head> 
 <body> 
  <a class="offline-button" href="../index.html">Back</a> 
  <div id="example"> 
   <div class="demo-section k-content"> 
    <div id="target" data-bind="slide: slideValue">
      One Big Orange Spot. 
    </div> 
    <div> 
     <h4>Slide Binding</h4> 
     <label> Toggle: <input type="checkbox" data-bind="checked: slideValue"> </label> 
    </div> 
   </div> 
   <script>
        kendo.data.binders.slide = kendo.data.Binder.extend( {
            refresh: function() {
                var value = this.bindings["slide"].get();

                if (value) {
                    $(this.element).slideDown();
                } else {
                    $(this.element).slideUp();
                }
            }
        });

        $(document).ready(function() {
            var viewModel = kendo.observable({
                slideValue: true
            });

            kendo.bind($("#example"), viewModel);
        });
    </script> 
   <div class="box wide"> 
    <h4>View source code:</h4> 
    <pre class="prettyprint">
<div id="target" data-bind="slide: slideValue">
    One Big Orange Spot.
</div>
<label>
    Toggle: <input type="checkbox" data-bind="checked: slideValue" />
</label>
        </pre> 
    <h4 style="padding-top: 2em;">Custom binder source code:</h4> 
    <pre class="prettyprint">
kendo.data.binders.slide = kendo.data.Binder.extend( {
    refresh: function() {
        var value = this.bindings["slide"].get();

        if (value) {
            $(this.element).slideDown();
        } else {
            $(this.element).slideUp();
        }
    }
});
        </pre> 
    <h4 style="padding-top: 2em;">View model source code:</h4> 
    <pre class="prettyprint">
var viewModel = kendo.observable({
    slideValue: true
});

kendo.bind($("#example"), viewModel);
        </pre> 
   </div> 
   <style>
        #target {
            width: 100%;
            border-width: 4px;
            padding: 2em;
            display: block;
            box-sizing: border-box;
            margin: 0 auto 30px;
            background-color: gold;
            color: darkRed;
            border-style: solid;
            border-color: darkOrange;
            border-radius: 10px;
            -webkit-border-radius: 10px;
            -ms-border-radius: 10px;
            -moz-border-radius: 10px;
            text-align: center;
            vertical-align: middle;
        }

        .prettyprint {
            background-color: #fff;
            border: 1px solid #ccc;
            overflow: auto;
            padding: 5px;
        }
    </style> 
  </div>   
 </body>
</html>