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库。

Kendo UI通过继承基本窗口小部件类为您提供创建自定义窗口小部件的选项。

处理事件

1. 将更改事件绑定到您的数据源并处理它。在这里您可以根据从数据源读取的数据来更改DOM,通常这是通过刷新方法完成的。将其公开,以便您或其他人能够在初始化后的某个时刻在小部件上调用它。

// Bind to the change event to refresh the widget.

  that.dataSource.bind("change", function() {
that.refresh();
});

下面的示例演示了小部件代码的外观。 请注意,当您绑定到数据源上的change事件时,实际上是绑定到字符串值“ change”。最佳的做法是在小部件顶部将它们分配为常量,然后引用该常量,整个DataSource配置也移到自己的方法中。这是因为that表示窗口小部件,因为that是调用对象。您可以将that分配给this对象后,引用that对象的所有窗口小部件属性。

(function($) {
var kendo = window.kendo,
  ui = kendo.ui,
  Widget = ui.Widget,
  CHANGE = "change";
var Repeater = kendo.ui.Widget.extend({
  init: function(element, options) {
  var that = this;
  kendo.ui.Widget.fn.init.call(that, element, options);
  // initialize or create dataSource
  that._dataSource();
  },
  options: {
  name: "Repeater"
  },
  _dataSource: function() {
  var that = this;
  // returns the datasource OR creates one if using an array or a configuration
  that.dataSource = kendo.data.DataSource.create(that.options.dataSource);
// Bind to the change event to refresh the widget
  that.dataSource.bind(CHANGE, function() {
  that.refresh();
  });
  }
  });
kendo.ui.plugin(Repeater);
})(jQuery);
  <!--_-->

2. 通过检查that.options的autoBind配置值从数据源获取(如有必要),然后调用that.dataSource.fetch()。请注意fetch和read不同,因为仅当尚未从DataSource读取数据时,它才会填充DataSource。如果在初始化小部件之前在DataSource上调用了read,则不要使DataSource再次读取。

_dataSource: function() {var that = this;
// Returns the datasource OR creates one if using array or configuration.
  that.dataSource = kendo.data.DataSource.create(that.options.dataSource);
// Bind to the change event to refresh the widget.
  that.dataSource.bind(CHANGE, function() {
  that.refresh();
  });
// Trigger read on the dataSource if one has not happened yet.
  if (that.options.autoBind) {
  that.dataSource.fetch();
  }
  }

3. 将autoBind配置添加到小部件上的options对象,并将其默认值设置为true。 Kendo UI中的所有数据绑定窗口小部件在默认情况下都自动绑定。

options: {
name: "Repeater",
autoBind: true
}
带有模板的渲染小部件

1. 小部件输出的HTML会在Kendo UI模板上呈现,它们允许您预编译HTML并将经过评估的数据或表达式注入HTML中,并且DOM片段作为HTML字符串返回。Kendo UI中几乎所有的小部件都允许您指定除小部件使用的默认模板之外的某种模板,为此首先将模板添加到options对象,并将其值设置为空字符串。 与其他配置设置相反,请勿在此处设置其默认值。

options: {
name: "Repeater",
autoBind: true,
template: ""
}

2. 通过直接在基本小部件初始化的调用下添加一行来设置默认值,这将预编译用户传入的模板,或使用默认模板。对于此Repeater,写出封装在段落中strong标签,然后引用数据对象。如果我们传递字符串数组,则该数据对象将是一个字符串。 如果将对象传递给模板,则默认模板将呈现[object Object]。

that.template = kendo.template(that.options.template || "
#= data #
")
实施刷新功能

1. 由于绑定到change方法,因此需要实现在数据源更改或直接调用时将调用的refresh公共函数。在refresh方法内部,您将要更改DOM。首先调用that.dataSource.view(),它将为您提供来自DataSource的数据;接下来使用kendoRender并将模板与DataSource data—a.k.a.视图一起传递,Kendo UI窗口小部件就是这样改变DOM的。render方法将数据应用于DataSource并返回HTML字符串。

refresh: function() {
var that = this,
view = that.dataSource.view(),
html = kendo.render(that.template, view);
}

2. 设置that.element的HTML —在其上初始化小部件的元素。如果要处理输入的初始化,并且想用容器转换或包装该输入,请在设置HTML之前在此处添加该逻辑。that.element是jQuery包装的元素,因此您可以直接从其中调用html方法。最终的刷新方法类似于下面示例中演示的方法。

refresh: function() {var that = this,view = that.dataSource.view(),html = kendo.render(that.template, view);
that.element.html(html);
  }

3. 在上一步中添加了最后的修饰后,现在您有一个完全数据绑定的小部件。 以下示例演示了Repeater小部件的完整代码。

(function() {var kendo = window.kendo,ui = kendo.ui,Widget = ui.Widget,
CHANGE = "change";
var Repeater = Widget.extend({
  init: function(element, options) {
  var that = this;
kendo.ui.Widget.fn.init.call(that, element, options);
  that.template = kendo.template(that.options.template || "<p><strong>#= data #</strong></p>");
that._dataSource();
  },
  options: {
  name: "Repeater",
  autoBind: true,
  template: ""
  },
  refresh: function() {
  var that = this,
  view = that.dataSource.view(),
  html = kendo.render(that.template, view);
that.element.html(html);
  },
  _dataSource: function() {
  var that = this;
  // Returns the datasource OR creates one if using array or configuration object.
  that.dataSource = kendo.data.DataSource.create(that.options.dataSource);
// Bind to the change event to refresh the widget.
  that.dataSource.bind(CHANGE, function() {
  that.refresh();
  });
if (that.options.autoBind) {
  that.dataSource.fetch();
  }
  }
  });
ui.plugin(Repeater);
})(jQuery);

以下示例使用两个已初始化的窗口小部件。 第一个将简单数组作为数据源;第二个使用远程端点、模板和声明式初始化。

<div id="repeater"></div>
<div id="container">
  <div data-role="repeater" data-source="dataSource" data-template="template"></div>
  </div>
<script type="text/x-kendo-template" id="template">
  <div style="float: left; color: salmon; margin-right: 10px"><h1>#= data.ProductName #</h1></div>
  </script>
<script>
  (function() {
  var kendo = window.kendo,
  ui = kendo.ui,
  Widget = ui.Widget,
CHANGE = "change";
var Repeater = Widget.extend({
  init: function(element, options) {
  var that = this;
kendo.ui.Widget.fn.init.call(that, element, options);
  that.template = kendo.template(that.options.template || "<p><strong>#= data #</strong></p>");
that._dataSource();
  },
  options: {
  name: "Repeater",
  autoBind: true,
  template: ""
  },
  refresh: function() {
  var that = this,
  view = that.dataSource.view(),
  html = kendo.render(that.template, view);
that.element.html(html);
  },
  _dataSource: function() {
  var that = this;
  // Returns the datasource OR creates one if using array or configuration object.
  that.dataSource = kendo.data.DataSource.create(that.options.dataSource);
// Bind to the change event to refresh the widget.
  that.dataSource.bind(CHANGE, function() {
  that.refresh();
  });
if (that.options.autoBind) {
  that.dataSource.fetch();
  }
  }
  });
ui.plugin(Repeater);
})(jQuery);
var dataSource = new kendo.data.DataSource({
  type: "odata",
  transport: {
  read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Products"
  }
  });
kendo.bind($("#container"));
$("#repeater").kendoRepeater({
  dataSource: [ "item1", "item2", "item3" ]
  });
  </script>

Kendo UI R3 2019全新发布,最新动态请持续关注Telerik中文网!

扫描关注慧聚IT微信公众号,及时获取最新动态及最新资讯

Web UI开发推荐!Kendo UI for jQuery自定义小部件——处理事件的更多相关文章

  1. [置顶] Kendo UI开发教程: Kendo UI 示例及总结

    前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...

  2. Web UI开发推荐!Kendo UI for jQuery自定义小部件——使用MVVM

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  3. Kendo UI for jQuery自定义小部件第一弹!不得不看的入门指南

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  4. Web UI开发神器—Kendo UI for jQuery数据管理网格编辑操作

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  5. Web UI开发神器—Kendo UI for jQuery数据管理之过滤操作

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  6. HTML5 Web app开发工具Kendo UI Web中如何绑定网格到远程数据

    在前面的文章中对于Kendo UI中的Grid控件的一些基础的配置和使用做了一些介绍,本文来看看如何将Kendo UI 中的Grid网格控件绑定到远程数据. 众所周知Grid网格控件是用户界面的一个重 ...

  7. HTML5 Web app开发工具Kendo UI Web中Grid网格控件的使用

    Kendo UI Web中的Grid控件不仅可以显示数据,并对数据提供了丰富的支持,包括分页.排序.分组.选择等,同时还有着大量的配置选项.使用Kendo DataSource组件,可以绑定到本地的J ...

  8. 免费UI框架推荐--Charisma UI

    基于Jquery.Bootstrap的后台管理免费UI框架推荐--Charisma UI 在项目设计和开发工作中,做过一些后台管理系统的设计和开发,用的很多都是比较传统的UI框架. 老是走在这个圈子里 ...

  9. Web前端开发推荐阅读书籍、学习课程下载

    转自http://www.xuanfengge.com/fe-books.html 前言 学校里没有前端的课程,那如何学习JavaScript,又如何使自己成为一个合格的前端工程师呢? 除了在项目中学 ...

随机推荐

  1. linux下安装mysql5.7方法与常见问题

    linux上安装mysql5.7 1.下载tar包,这里使用wget从官网下载 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7 ...

  2. 上传下载文件到Linux服务器

    转自链接:https://blog.csdn.net/drdongshiye/article/details/89430535Mac的终端是十分强大 , 可以通过命令进行上传下载下载文件夹 scp - ...

  3. 【ActiveReports 大数据分析报告】2019国庆旅游出行趋势预测

    今年国庆假期全国接待国内游客人数有望达到8亿人次! 随着2019国庆小长假的临近,不少游客已经开始着手规划假期出游路线.据权威机构发布的<2019国庆旅游趋势预测报告>显示,今年“十一黄金 ...

  4. 什么时候该使用SUM()函数

    SUM函数用于返回表达式中所有值的和.通常情况下,对某些数据进行汇总时会用到该函数. 语法:SELECT SUM(column_name) FROM table_name

  5. 【LOJ】#3093. 「BJOI2019」光线

    LOJ#3093. 「BJOI2019」光线 从下到上把两面镜子合成一个 新的镜子是\((\frac{a_{i}a_{i + 1}}{1 - b_{i}b_{i + 1}},b_{i} + \frac ...

  6. git安装配置相关

    Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括Rubinius ...

  7. Linux系列:进阶之tomcat安装

    思路:作者是在Windows上从Apache官网下载的tomcat,之后将tomcat文件放到我的ftp站点中,在Linux访问ftp站点下载tomcat文件 ,将tomcat放在我自己的安装目录中, ...

  8. STL priority_queue 常见用法详解

    <算法笔记>学习笔记 priority_queue 常见用法详解 //priority_queue又称优先队列,其底层时用堆来实现的. //在优先队列中,队首元素一定是当前队列中优先级最高 ...

  9. Thinkphp5 自定义上传文件名

    这几天在做tp5的上传文件模块,项目需求是要把文件名在上传之后修改为 用户名+原文件名的组合形式,在网上找了一会儿发现好像没有类似的文章...只好自己去研究研究了. 之前查看过看云上面的官方手册,文件 ...

  10. Python开发之JavaScript

    JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. 一.如何编写 1.J ...