kendo ui 实现MVVM

MVVM                    model----view model----model 实现页面和model之间的动态绑定

grid 支持 events  source  visible绑定

第一步建立一个observable对象   对象为参数

var viewModel = kendo.observable()

第二步实现视图与 viewModel绑定

 kendo.bind($("#example"), viewModel);  //jQuery对象

注意对某一属性设置值时使用

this.set("isDescriptionShown", true);  
     showDescription: function(e) {
       e.stopPropagation();      e.preventDefault();
        this.set("isDescriptionShown", true);  //给属性赋值   }



<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="styles/kendo.common.min.css" />
    <link rel="stylesheet" href="styles/kendo.default.min.css" />
    <link rel="stylesheet" href="styles/kendo.default.mobile.min.css" />

    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.all.min.js"></script>

</head>
<body>
<div id="example">
    <div class="demo-section k-content wide">
        <div>
            <h4>Add or update a record</h4>
            <div data-role="grid"
                 data-editable="true"
                 data-toolbar="[‘create‘, ‘save‘]"
                 data-columns="[
                                 { ‘field‘: ‘ProductName‘, ‘width‘: 270 },
                                 { ‘field‘: ‘UnitPrice‘ },
                              ]"
                 data-bind="source: products,   //绑定的属性
                            visible: isVisible,   //显示隐藏
                            events: {
                              save: onSave
                            }"
                 style="height: 200px"></div>
        </div>
        <div style="padding-top: 1em;">
            <h4>Console</h4>
            <div class="console"></div>
        </div>
    </div>
    <div class="box wide">
        <div class="box-col">
            <h4>Configuration</h4>
            <div>
                <label><input type="checkbox" data-bind="checked: isVisible">Visible</label>  //绑定的属性
            </div>
        </div>
        <div class="box-col">
            <h4>Information</h4>
            Kendo UI Grid supports the
            <a href="http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/bindings/events">events</a>,
            <a href="http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/bindings/source">source</a> and
            <a href="http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/bindings/visible">visible</a> bindings.
        </div>
    </div>
<script>
    var viewModel = kendo.observable({ //观察者 检测属性的变化
        isVisible: true,
        onSave: function(e) {
            kendoConsole.log("event :: save(" + kendo.stringify(e.values, null, 4) + ")");
        },
        products: new kendo.data.DataSource({
            schema: {  //图表
                model: {
                    id: "ProductID",
                    fields: {
                        ProductName: { type: "string" },
                        UnitPrice: { type: "number" }
                    }
                }
            },
            batch: true,  //批量的
            transport: {
                read: {
                    url: "https://demos.telerik.com/kendo-ui/service/products",
                    dataType: "jsonp"
                },
                update: {
                    url: "https://demos.telerik.com/kendo-ui/service/products/update",
                    dataType: "jsonp"
                },
                create: {
                    url: "https://demos.telerik.com/kendo-ui/service/products/create",
                    dataType: "jsonp"
                },
                parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return {models: kendo.stringify(options.models)};
                    }
                }
            }
        })
    });
    kendo.bind($("#example"), viewModel);  //实现  视图和 viewModel的绑定
</script>
</div>

</body>
</html>

原文地址:https://www.cnblogs.com/baota/p/8983325.html

时间: 2024-08-30 11:11:45

kendo ui 实现MVVM的相关文章

Kendo UI for jQuery使用教程:使用MVVM初始化(一)

[Kendo UI for jQuery最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support for React和Kendo UI Support for Vue四个控件.Kendo UI for jQuery是创建现代Web应用程序的最完整UI库. 您可以通过数据属性或基于自定义HTML属性初始化和配置每个Kendo UI小部件. Kendo UI混合应用程序.单页面应用程序(SPA)视

Kendo UI常用示例汇总(十四)

Kendo UI Professional 提供开源和商业两个版本.开源版 Kendo UI Core,有40+个框架和组件:商业版整合了之前的Kendo UI Web.Kendo UI Mobile 和 Kendo UI DataViz ,一共有70+个框架和组件.作为Kendo UI的升级版,Kendo UI Professional既可以开发网页版应用程序,也可以开发移动版应用程序,并且在性能上也有显著的优化和提升. Kendo UI Professional试用版下载猛戳>> Kend

Telerik Kendo UI 那点事【3】

中文化之后,我们开始具体使用kendo ui组件.经常开发系统的我,通常从最常用的控件用起,那就是表格控件GridView!现在的软件系统基本上就是标签框.文本框.选择框.树.表格堆砌而成.因此接触任何一种UI组件的时候,我通常都最为关注GridView,表格控件.小小的表格控件,做的好,能够给前端呈现和使用带来很好的感受的同时,还能够大幅度降低开发的工作量. Kendo UI在这方面让我十分满意,甚至是震惊.因为它的GridView不仅仅是能够简单的在呈现层进行数据的过滤.排序.分组,关键是还

两大HTML5框架评测:Kendo UI 和 jQuery Mobile

jQuery Mobile 和 Kendo UI 都是流行的 JavaScript 框架,在开发中我们可以在它们的基础上添砖加瓦制作所有现代移动WEB应用.这两个框架都是基于使用率顶尖的 JavaScript 库 jQuery 所构建的.比较 Kendo UI 和 jQuery Mobile 有些类似于比较同一枚硬币的两面.众所周知,jQuery Mobile 实际上并不需要太多的介绍,因为它是最常用的HTML5框架之一. Kendo UI 具有相似的动机和类似的发展速度.与 jQuery Mo

Kendo UI常用示例汇总(六)

Kendo UI Professional 提供开源和商业两个版本.开源版 Kendo UI Core,有40+个框架和组件:商业版整合了之前的Kendo UI Web.Kendo UI Mobile 和 Kendo UI DataViz ,一共有70+个框架和组件.作为Kendo UI的升级版,Kendo UI Professional既可以开发网页版应用程序,也可以开发移动版应用程序,并且在性能上也有显著的优化和提升. Kendo UI Professional试用版下载猛戳>> Kend

Kendo UI

Kendo UI is an HTML5, jQuery-based framework for building modern web apps. The framework features lots of UI widgets, a rich data visualization framework, an auto-adaptive mobile framework, and all the tools needed for HTML5 app development, such as

Telerik Kendo UI 那点事【2】

CSDN上有一个引路蜂软件的博客,里面有kendo ui的一般用法.它那里讲过的我这里就不再继续重复. 由于框架设计的需要,后台使用spring,前台使用kendo ui构建页面.为了加快快发速度以及底层兼容性,义不容辞的,继续选择了hibernate作为数据库沟通的桥梁.spring方面的例子全网就更多了,主要采用spring注解方式的MVC配置,使用json数据映射器. 经过初步的使用,发现kendo ui的设计极为强大,其MVVM的特性与spring的MVC特性结合,配合hibernate

[转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse &amp; Generic Unit of Work Repository Framework v2.0

本文转自:http://www.tuicool.com/articles/BBVr6z Thanks to everyone for allowing us to give back to the .NET community, we released v1.0 of the Generic Unit of Work and Repository Framework for four weeks and received 655 downloads and 4121 views. This po

Kendo UI常用示例汇总(十三)

Kendo UI Professional 提供开源和商业两个版本.开源版 Kendo UI Core,有40+个框架和组件:商业版整合了之前的Kendo UI Web.Kendo UI Mobile 和 Kendo UI DataViz ,一共有70+个框架和组件.作为Kendo UI的升级版,Kendo UI Professional既可以开发网页版应用程序,也可以开发移动版应用程序,并且在性能上也有显著的优化和提升. Kendo UI Professional试用版下载猛戳>> Kend