(三)关于kendo IU表单form各类控件的数据绑定

=====================input textarea=============================
<div id="view">
    <input data-bind="value: inputValue" />
    <textarea data-bind="value: textareaValue"></textarea>
</div>
<script>
var viewModel = kendo.observable({
    inputValue: "Input value",
    textareaValue: "Textarea value"
});
kendo.bind($("#view"), viewModel);
</script>
备注:
当触发事件时才执行绑定,需要在input或textarea标签里加
data-value-update="keyup"
或
data-value-update="keypress"
=====================textarea,dropdownlist=============================
<select data-text-field="name" data-value-field="id" data-bind="source: products,value:names" multiple="multiple"></select>
<script>
var viewModel = kendo.observable({
products: [
    { id: 1, name: "Coffee" },
    { id: 2, name: "Tea" },
    { id: 3, name: "Juice" }
],
names: ["Tea","Juice"],
});
kendo.bind($("select"), viewModel);
备注:绑定的value:names在绑定的source: products生效前会失效,所以两个不能同时用,只能通过在绑定source: products后用jquery实现:
$("select").val(["Tea","Juice"]);
</script>
===============
Kendo UI dropdown list级联菜单刷新:
在父dropdown list上绑定change事件函数:change : onItemChange
在函数中刷新更新子dropdow list的数据源(data source)
var subDDList = $(‘#subListDiv‘).data("kendoDropDownList");
subDDList.setDataSource(buildSubList(selectParentId));
=====================select=============================
<select data-bind="source: colors"></select>
<script>
var viewModel = kendo.observable({
    colors: [ "Red", "Green", "Blue" ]
});
kendo.bind($("select"), viewModel);
</script>
=====================
<select data-text-field="name" data-value-field="id" data-bind="source: products"></select>
<script>
var viewModel = kendo.observable({
    products: [
        { id: 1, name: "Coffee" },
        { id: 2, name: "Tea" },
        { id: 3, name: "Juice" }
    ]
});
kendo.bind($("select"), viewModel);
</script>
====================================上传组件==========================================
上传文件对话框使用
$("#selectedFiles").kendoUpload({
    async: {
        saveUrl:  "myDomain/fileUpload.htm",
        autoUpload: true
    },
    multiple:true, // 支持多个文件上传,
    complete: uploadFileComplete, //上传结束以后处理,
    error: onError,
    cancel: onCancel,
    select: onSelect,
    success: onSuccess
});
调用代码 $("#selectedFiles ").click();//模拟鼠标双击事件调用,
页面上selectedFileshtml元素为隐藏对象。

=========================checkbox多选框绑定==================================
<input type="checkbox" value="Red" data-bind="checked: colors" />Red
<input type="checkbox" value="Green" data-bind="checked: colors" />Green
<input type="checkbox" value="Blue" data-bind="checked: colors" />Blue
<script>
    var viewModel = kendo.observable({
        colors: ["Red","Green"]
    });

    kendo.bind($("input"), viewModel);
</script>
=======================
<input type="checkbox" data-bind="checked: isChecked" />
<script>
var viewModel = kendo.observable({
    isChecked: false
});

kendo.bind($("input"), viewModel);
</script>
=========================rado单选按钮绑定==================================
<input type="radio" value="Red" name="color" data-bind="checked: selectedColor" />Red
<input type="radio" value="Green" name="color" data-bind="checked: selectedColor" />Green
<input type="radio" value="Blue" name="color" data-bind="checked: selectedColor" />Blue
<script>
    var viewModel = kendo.observable({
        selectedColor: "Green"
    });

    kendo.bind($("input"), viewModel);
</script>
=========================UL LI模板绑定==================================
<ul data-template="ul-template" data-bind="source: products">
</ul>
<script id="ul-template" type="text/x-kendo-template">
    <li>
        id: <span data-bind="text: id"></span>
        name: <span data-bind="text: name"></span>
    </li>
</script>
<script>
var viewModel = kendo.observable({
    products: [
        { id: 1, name: "Coffee" },
        { id: 2, name: "Tea" },
        { id: 3, name: "Juice" }
    ]
});

kendo.bind($("ul"), viewModel);
</script>
===========================UL LI模板一维数组数据绑定=========================
<ul data-template="ul-template" data-bind="source: products">
</ul>
<script id="ul-template" type="text/x-kendo-template">
    <li data-bind="text: this"></li>
</script>
<script>
var viewModel = kendo.observable({
    products: [ "Coffee", "Tea", "Juice" ]
});

kendo.bind($("ul"), viewModel);
</script>
=====================span text=============================
<span data-bind="text: name"></span>
<script>
var viewModel = kendo.observable({
name: "John Doe"
});
kendo.bind($("span"), viewModel);
</script>
=====================span html==============================
<span data-bind="html: name"></span>
<script>
var viewModel = kendo.observable({
name: "<strong>John Doe</strong>"
});
kendo.bind($("span"), viewModel);
</script>
=====================invisible 显示不显示==============================
<div id="view">
<div data-bind="invisible: isInvisible">some content</div>
<button data-bind="click: show">Show</button>
</div> 

<script>
var viewModel = kendo.observable({
isInvisible: true,
show: function () {
this.set("isInvisible", false);
}
});
kendo.bind($("#view"), viewModel);
</script>

=====================disabled 有效没有效==============================
<div id="view">
<input type="text" data-bind="value: name, disabled: isNameDisabled" />
<button data-bind="click: disableInput">Disable</button>
</div>
<script>
    var viewModel = kendo.observable({
        isNameDisabled: false,
        name: "John Doe",
        disableInput: function () {
            this.set("isNameDisabled", true);
        }
    });

    kendo.bind($("#view"), viewModel);
</script>
=======================style 动态改变样式===============================
<span data-bind="style: {color: priceColor, fontWeight: priceFontWeight},text: price"></span>
<script>
    var viewModel = kendo.observable({
        price: 42,
        priceColor: function() {
            var price = this.get("price");
            if (price <= 42) {
                return "#00ff00";
            } else {
                return "#ff0000";
            }
        },
        priceFontWeight: function() {
            var price = this.get("price");
            if (price <= 42) {
                return "bold";
            } else {
                return "";
            }
        }
    });
    kendo.bind($("span"), viewModel);
</script>
要注意的是CSS属性的名称,如果CSS名称中含有连字符(-),比如font-weight, font-size ,background-color等,在使用时需要省略到连字符,使用camel风格的命名,如fontWeight, fontSize,backgroundColor等。
========================上层绑定=============================
<div data-template="div-template" data-bind="source: person">
    <script id="div-template" type="text/x-kendo-template">
    Name: <span data-bind="text: name"></span>
    </script>
</div>
<script>
var viewModel = kendo.observable({
    person: {
        name: "John Doe"
    }
});
kendo.bind($("div"), viewModel);
</script>
========================上层单维数据绑定=============================
<div data-template="div-template" data-bind="source: this">
    <script id="div-template" type="text/x-kendo-template">
    Name: <span data-bind="text: name"></span>
    </script>
</div>
<script>
var viewModel = kendo.observable({
    name: "John Doe"
});

kendo.bind($("div"), viewModel);
</script>

========================属性绑定=============================
<img id="logo" data-bind="attr: { src: imageSource, alt: imageAlt }" />
<script>
var viewModel = kendo.observable({
    imageSource: "http://www.kendoui.com/image/kendo-logo.png",
    imageAlt: "Kendo Logo"
});

kendo.bind($("#logo"), viewModel);
</script>
========================
<div data-bind="attr: { data-foo: fooValue, data-bar: barValue }"></div>
 <script>
var viewModel = kendo.observable({
    fooValue: "foo",
    barValue: "bar"
});
 kendo.bind($("div"), viewModel);
</script>
========================最后介绍远程数据=============================
<script>
var sharableDataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: "data-service.json",
            dataType: "json"
        }
    }
}); 

var dataSource = new kendo.data.DataSource({
    transport: {
    read: {
        url: "http://t.sogx.cn/api/data/getQzxx.php",
        dataType: "jsonp",
        data: {
        q: "html5"
        }
    }
    },
    schema : {
    data : function(d) {
        return d.data;   //响应到页面的数据
    },
    total : function(d) {
        return d.count;   //总条数
    }
    }
});

var viewModel = kendo.observable({
    products=dataSource;
});

kendo.bind($("div"), viewModel);
</script>
====================
<?php
header(‘Content-Type:text/html;charset=GB2312‘);
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Headers:x-requested-with");
include("d:/www.qmlt.com/global.php");
require(MODEL_PATH.‘class/common.php‘);
$db->query("set character set ‘GB2312‘");
$db->query("set names ‘GB2312‘");
$q=$_GET[‘q‘];
if($q==""){
    $sql="select id,name from qm_industry";
}else{
    $sql="select id,name from qm_job_class where keyid=‘$q‘";
}
$ku=$db->query($sql);
$result=array();
$i=0;
while($rs=$db->fetch_array($ku)){
    $result[‘data‘][$i][‘id‘]=$rs[id];
    $result[‘data‘][$i][‘name‘]=(trim(u($rs[name]))!="")?u($rs[name]):"(未命名)";
    $i++;
}
$result[‘count‘]=$i;
echo  $_GET[‘callback‘]."(".json_encode($result).")";
?>

(三)关于kendo IU表单form各类控件的数据绑定

时间: 2024-10-24 06:34:53

(三)关于kendo IU表单form各类控件的数据绑定的相关文章

响应式的账号登录界面模板完整代码,内置form表单和js控件

响应式的账号登录界面模板,内置form表单和js控件 1 <!DOCTYPE html> 2 <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 3 4 <link type="text/css" rel="styleSheet"

Html5之基础-9 HTML表单、其他控件、其他常用标记

一.表单概述 表单的作用 (1) 表单用于显示.收集信息,并提交信息到服务器 (2) 表单有两个基本部分 - 实现数据交互的可见的界面元素,比如文本框或按钮 - 提交后的表单处理 (3) 页面元素 - 使用 <form> 元素创建表单 - 在 <form> 元素中添加其他表单可以包含的控件元素 如图: 表单元素 <form> (1) 定义表单:使用成对的 <form></form>标记 (2) 主要属性 - action:  定义表单被提交时发生

[转]html5表单上传控件Files API

表单上传控件:<input type="file" />(IE9及以下不支持下面这些功能,其它浏览器最新版本均已支持.) 1.允许上传文件数量 允许选择多个文件:<input type="file" multiple> 只允许上传一个文件:<input  type="file" single> 2.上传指定的文件格式 <input type="file" accept="im

Extjs4——表单与输入控件

1.表单的简单形式: var form = new Ext.form.FormPanel({ title: 'form', defaultType: 'textfield', buttonAlign: 'center', frame: true, width: 220, fieldDefaults: { labelAlign: 'right', labelWidth: 70 }, items: [{ fieldLabel: '文本框' }], buttons: [{ text: '按钮' }]

深入浅出ExtJS 第四章 表单与输入控件(未完)

1 4.1 制作表单 2 var form = new Ext.form.FormPanel({ 3 title:'form', 4 defaultType:'textfield', 5 buttonAlign:'center', 6 frame:true, 7 width:220, 8 fieldDefaults:{ 9 labelAlign:'right', 10 labelWidth:70 11 }, 12 tiems:[{ //子组件; 13 fieldLabel:'文本框' //文本框

.Net Core使用视图组件(ViewComponent)封装表单文本框控件

实例程序的界面效果如下图所示: 在表单中的搜索条件有姓名,学号,成绩.他们在一行中按照水平三等分排列. 在cshtml中用html实现上述表单效果的的代码如下: 1 <form class="form-horizontal" role="form"> 2 <div class="row"> 3 <div class="form-group col-md-4"> 4 <label for

2017年12月17日 ASP.NET 12个表单元素&amp;&amp;简单控件/复合控件

12个表单元素可以分为三大类 第一类:文本类 <input type = "text" /> //普通文本框 <input type = "password" /> //密码文本框 <input type = "hidden" /> //隐藏域 <textrea></textrea> //可变动文本框 第二类:按钮类 <input type = "button"

PHP+JavaScript+HTML实现注册界面表单及日历控件

本文主要是介绍我做PHP网站时的一个HTML的简单静态界面,它的主要功能是用户注册界面,并且参照了网上的例子使用JavaScript判断和My97DatePicker的日历控件.界面效果如下图所示: 同时插入数据库显示效果如下图所示: 可以看到引用My97DatePicker的日历控件及判断效果如下图所示:    其中注册界面register_student.html代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona

easy ui 表单元素input控件后面加说明(红色)

<%-- 上传图片到图库基本信息且将图片关联到图集 开始--%> <div id="win_AddPicLib" class="easyui-window" title="添加图片信息" data-options="top:'30%'" style="width: 800px; height: 350; padding: 5px;"> <div style="padd