Home Web Front-end CSS Tutorial Data binding in HTML_CSS/HTML

Data binding in HTML_CSS/HTML

May 16, 2016 pm 12:12 PM

信息来源:Wayne_Deng的专栏

有没想过在java script中使用recordset?原来在客户端操作数据也可以这样简单,定义一个数据源,将数据绑定在各种tag上,实现应用程序般的效果,酷毙了!(首先申明一点,文章的内容全部来自msdn,不过用我自己的话总结而已。)

先看看这样两个例子:
http://msdn.microsoft.com/workshop/samples/author/databind/dbevts.htm
http://msdn.microsoft.com/workshop/samples/author/databind/dbupdate.htm
不得不又一次佩服微软。

这个是DataBinding的架构:
架构
当然实现数据绑定有下面几步:

第一步,定义数据源
从IE4.0起,就支持下面四种数据源:



Tabular Data Control (TDC)
TDC提供了一个简单的访问带有格式的文本数据的方法,一般是csv文件。
下面是一个简单的示例:

ID=dsoComposer WIDTH=0 HEIGHT=0>
    



Remote Data Service (RDS)
远程数据服务,直接访问远程服务器端的数据,Internet Explorer 4.0. RDS 通过OLE-DB 或 Open Database Connectivity (ODBC)来实现。

示例:

ID=dsoComposer HEIGHT=0 WIDTH=0>
    
    
    

不过感觉有点安全性的问题,因为客户端能看到这段代码。

XML Data Source
XML就不多说了,在IE4.0中这样使用:
CODE="com.ms.xml.dso.XMLDSO.class"
ID="xmldso"
WIDTH="0"
HEIGHT="0"
MAYSCRIPT="true">
    


Internet Explorer 5以上可以这样:



另外IE还提供了一个XML数据岛的概念:XML Data Islands.

 
MSHTML Data Source
html数据页示例:

Hector


Berlioz
1803

Modest


Moussorgsky




Liszt
1811

一旦定义可以这样访问:



.第二步:绑定数据到HTML元素上
一般都是通过tag中的datasrc和datafld实现绑定的。例如:







这个是绑定表格的示例:
http://msdn.microsoft.com/workshop/samples/author/databind/dbtable.htm

其中数据来源:

           
 
 

绑定的table


   
   


   
   
   
   
   


FirstLastBirthDeathOrigin

This is the effect:
First Last Birth Death Origin
Hector Berlioz 1803 1869 France
Modest Moussorgsky 1839 1881 Russia
Franz Liszt 1811 1886 France
Antonio Vivaldi 1678 1741 Italy
Johann Sebastian Bach 168 5 1750 Germany
Ludwig van Beethoven 1770 1827 Germany
Wolfgang Amadeus Mozart 1756 1791 Austria
Joseph Haydn 1732 1809 Germany
Claude Debussy 1862 1918 France


The third step: dynamic addition, deletion, etc. of data (object model)
Of course Binding can be dynamic:
In script:
span1.dataSrc = "#dsoComposer";
span1.dataFld = "compsr_first";

html is like this:

And you can access the ado of the data source:
var oRecordSet = dsoComposer.recordset;
Of course there is oRecordSet .MoveNext and so on.

For example:
onclick="tdcComposers.recordset.MoveFirst()">
onclick="tdcComposers.recordset.MovePrevious();
if (tdcComposers.recordset.BOF)
tdcComposers.recordset.MoveFirst();"> ;
onclick="tdcComposers.recordset.MoveNext();
if (tdcComposers.recordset.EOF)
tdcComp osers.recordset .MoveLast();">
onclick="tdcComposers.recordset.MoveLast()">

It can also be used like this:


Just add and delete records : oRecordSet.AddNew() and oRecordSet.Delete().

Step 3: Respond to various data events (event model)
How to handle the data accordingly after it changes?
The method provided in msdn is as follows:

These are the list of event names:

Event Bubbles Cancelable Applies to Introduced In Internet Explorer Version
onbeforeupdate True True bound elements 4.0
onafterupdate True False bound elements 4.0
onrowenter True False D SO 4.0
onrowexit True False DSO 4.0
onbeforeunload False False window 4.0
ondataavailable True False DSO 4.0
ondatasetcomplete True False DSO 4.0
ondatasetchanged True False DSO 4.0
onerrorupdate True True bound elements 4.0
onreadystatechange True False DSO 4.0
oncellchange True False DSO 5.0
onrowsinserted True False DSO 5.0
onrowsdelete True False DSO 5.0 How about ?
I think http://msdn.microsoft.com/workshop/samples/author/databind/dbevts.htm is a relatively comprehensive example of application. If you study it carefully, you will definitely gain something.

There are many examples of using data binding to achieve paging on the Internet. In fact, data binding can do more things, right? There should be very large applications in rich clients, such as making very complex datagrids.

What I want to find out more now is how to easily achieve synchronization with the server, because the client's data binding has no impact on the server (you can generate data sources from the server, but the operations on the client do not will automatically return to the server), msdn says that RDS can be used, but this method is too clumsy and unsafe.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
A Comparison of Static Form Providers A Comparison of Static Form Providers Apr 16, 2025 am 11:20 AM

Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

Weekly Platform News: HTML Loading Attribute, the Main ARIA Specifications, and Moving from iFrame to Shadow DOM Weekly Platform News: HTML Loading Attribute, the Main ARIA Specifications, and Moving from iFrame to Shadow DOM Apr 17, 2025 am 10:55 AM

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

Some Hands-On with the HTML Dialog Element Some Hands-On with the HTML Dialog Element Apr 16, 2025 am 11:33 AM

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

Paperform Paperform Apr 16, 2025 am 11:24 AM

Buy or build is a classic debate in technology. Building things yourself might feel less expensive because there is no line item on your credit card bill, but

Where should 'Subscribe to Podcast' link to? Where should 'Subscribe to Podcast' link to? Apr 16, 2025 pm 12:04 PM

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

Weekly Platform News: Text Spacing Bookmarklet, Top-Level Await, New AMP Loading Indicator Weekly Platform News: Text Spacing Bookmarklet, Top-Level Await, New AMP Loading Indicator Apr 17, 2025 am 11:26 AM

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

Options for Hosting Your Own Non-JavaScript-Based Analytics Options for Hosting Your Own Non-JavaScript-Based Analytics Apr 15, 2025 am 11:09 AM

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

See all articles