欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

BootStrap智能表單實(shí)戰(zhàn)系列(六)表單編輯頁(yè)面的數(shù)據(jù)綁定

 更新時(shí)間:2016年06月13日 14:43:07   作者:程序有Bug  
這篇文章主要介紹了BootStrap智能表單實(shí)戰(zhàn)系列(六)表單編輯頁(yè)面的數(shù)據(jù)綁定的相關(guān)資料,一般用于編輯頁(yè)面,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下

什么是 Bootstrap?

Bootstrap 是一個(gè)用于快速開(kāi)發(fā) Web 應(yīng)用程序和網(wǎng)站的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的。

歷史

Bootstrap 是由 Twitter 的 Mark Otto 和 Jacob Thornton 開(kāi)發(fā)的。Bootstrap 是 2011 年八月在 GitHub 上發(fā)布的開(kāi)源產(chǎn)品。

Bootstrap 包的內(nèi)容

基本結(jié)構(gòu):Bootstrap 提供了一個(gè)帶有網(wǎng)格系統(tǒng)、鏈接樣式、背景的基本結(jié)構(gòu)。這將在 Bootstrap 基本結(jié)構(gòu) 部分詳細(xì)講解。

CSS:Bootstrap 自帶以下特性:全局的 CSS 設(shè)置、定義基本的 HTML 元素樣式、可擴(kuò)展的 class,以及一個(gè)先進(jìn)的網(wǎng)格系統(tǒng)。這將在 Bootstrap CSS 部分詳細(xì)講解。

組件:Bootstrap 包含了十幾個(gè)可重用的組件,用于創(chuàng)建圖像、下拉菜單、導(dǎo)航、警告框、彈出框等等。這將在 布局組件 部分詳細(xì)講解。

JavaScript 插件:Bootstrap 包含了十幾個(gè)自定義的 jQuery 插件。您可以直接包含所有的插件,也可以逐個(gè)包含這些插件。這將在 Bootstrap 插件 部分詳細(xì)講解。

定制:您可以定制 Bootstrap 的組件、LESS 變量和 jQuery 插件來(lái)得到您自己的版本。

本章介紹如何在生成表單后,將一個(gè)model的數(shù)據(jù)展示到form表單中(一般用于編輯頁(yè)面)

代碼如下(連接地址:https://github.com/xiexingen/Bootstrap-SmartForm/blob/master/demo/form4-initData.html):

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>數(shù)據(jù)綁定</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/bootstrap.css">
<!--自定義站點(diǎn)樣式-->
<link rel="stylesheet" href="../css/site.css">
<script src="../lib/jquery.js"></script>
<script src="../lib/bootstrap.js"></script>
<!--工具方法-->
<script src="../scripts/global.js"></script>
<!--插件-->
<script src="../scripts/plugin.js"></script>
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading">
<label>數(shù)據(jù)綁定</label>
<div class="pull-right">
<button id="btnSubmit" class="btn btn-primary btn-xs">提交表單</button>
</div>
</div>
<div class="panel-body">
<form action="#" id="formContainer" class="form form-horizontal"></form>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><label>介紹</label></div>
<div class="panel-body">
<h3 class="lead">表單數(shù)據(jù)綁定</h3>
<blockquote>
<p>將json格式的model綁定到表單中,此處使用模擬的model數(shù)據(jù),實(shí)際環(huán)境中應(yīng)該是與服務(wù)器交互取到數(shù)據(jù),在配置對(duì)象的是需要一個(gè)回調(diào)方法,在回到方法里面可以做表單的一些其他操作,如添加表單驗(yàn)證、添加日期插件的支持====</p>
<p>note:復(fù)選框的數(shù)據(jù)源為數(shù)組形式</p>
</blockquote>
</div>
</div>
<script>
$(function () {
var eles=[
[
{label:{text:'自定義用戶名:'},ele:{type:'text',name:'UserName',title:'用戶名:',required:true}},
{ele:{type:'radio',name:'sex',title:'性別:',items:[{text:'男',value:1},{text:'女',value:2}]}},
{ele:{type:'checkbox', name:'plant',title:'使用平臺(tái):',items:[{text:'APP',value:'app'},{text:'web',value:'web'}]}} 
],
[
{ele:{type:'select',name:'province',title:'省份:',withNull:true,items:[{text:'廣東',value:'GD'},{text:'湖南',value:'HN'}]}},
{ele:{pre:{text:'<input type="radio">'},type:'text',name:'displayName',title:'顯示名稱:'}},
{ele:{type:'search',title:'產(chǎn)品',id:'ProductName'}}
],
[
{ele:{type:'datetime',name:'FromeDate',title:'有效期:'}},
{ele:{type:'datetime',name:'ToDate',title:'~'}},
]
];
//隱藏表單元素主要用于編輯時(shí)候后臺(tái)可以區(qū)別開(kāi)來(lái)
var hides = [{ id: 'primaryKey' }];
var bsForm = new BSForm({ eles: eles, hides: hides, autoLayout: '1,3' }).Render('formContainer',function(bf){
var model={primaryKey:1,UserName:'xxg',sex:1,plant:['app','web'],province:'GD',displayName:'TEST',ProductName:'筆記本',FromeDate:'2015-06-10',ToDate:'2015-08-08'};
bf.InitFormData(model);
});
$("#btnSubmit").bind('click',function () {
var postData=bsForm.GetFormData();
alert("獲取到的表達(dá)數(shù)據(jù)為:"+JSON.stringify(postData));
})
});
</script>
</body></html> 

此處使用js創(chuàng)建了一個(gè)json類型的model,實(shí)際開(kāi)發(fā)情況下 會(huì)跟服務(wù)器交互得到一個(gè)model,通過(guò)表單插件的InitFormData方法將model顯示到form表單中

效果圖如下:


定義的數(shù)據(jù)成功顯示到表單中

note:針對(duì)復(fù)選框多選的情況下,需要返回的是一個(gè)數(shù)組

以上所述是小編給大家介紹的BootStrap智能表單實(shí)戰(zhàn)系列(六)表單編輯頁(yè)面的數(shù)據(jù)綁定的全部敘述,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論