Mvc+jquery Development B/s system (i) List binding (iii)

Source: Internet
Author: User
Tags bool json

In addition to binding the table, there are other looping lists that need to be bound.

In fact, all the same, are the template into data. The way in which a template is stored is a method of annotation. Better way to be free to play. Now it's just to get the template.

For example, use a JSON to store the template you need, and then place it in a templates.js or XML-configured template and generate JSON data, which can be used directly templates.tempname.

It's too tired to write posts. Especially when your thoughts are more tiring to share with others. I don't have to repeat it here. Put down the code.

Code

; (function ($) {
var templatelist = []; Store a generic list of templates

$.fn.bindlist = function (args, template, options, async) {
var me = this;

var url, async, template, DataSource;

url = me.attr ("datasource");
Async = Me.attr ("async") = = "0";
if (Arguments.length > 0) {
Switch (typeof (args)) {
Case "string":
url = args;
Break
Case "Object":
DataSource = args;
Break
}
}
Args is JSON
Switch (arguments.length) {
Case 1:
if (args = null)
return me;
if (typeof (args) = = "string") {
url = args;
}
else if (typeof (args) = = "Object") {
url = args.url;
Async = Args.async | | Async
Template = Args.template | | Template
Options = Args.options | | Options
DataSource = Args.data;
}
Break
Case 2://Url,async | | Url,tempalte | | Data,template
if (typeof (Arguments[0]) = = "string")
url = arguments[0];
Else
DataSource = Arguments[0];

if (typeof (arguments[1]) = = "bool") {
Async = Arguments[1];
Template = Me.gettemplate ();
}
Break
Case 3://url,template,async | | url,template,options | | Data,template,options
template = template;
options = options;
if (typeof (Options) = "bool") {
async = options;
options = undefined;
} break;
Case 4:
template = template;
options = options;
async = Async;
Break
}


if (url = = Undefined | | url = = "") && DataSource = = undefined) {
return me;
}

if (DataSource = = undefined) {
$.ajax ({
Type: "POST",
Async:async,
Url:url,
Success:function (data) {

if (data = = "" | | data = null)
Return
data = eval ("(+ Data +)");

Me.bindlistdata (data.list | | data, template, options);
}
});
}
else {
Me.bindlistdata (DataSource, template, Options);
}
return me;
};
$.fn.bindlistdata = function (data, template, options) {

var me = this;
Template = Template | | Me.gettemplate ();
This.empty ();
var resulttemplate = replacetemplate (template, data);


var prepend, append, Dvalue;
if (options!= undefined) {
prepend = Options.prepend;
append = Options.append;
Dvalue = Options.dvalue;
}

if (prepend!= undefined) {
Resulttemplate = prepend + resulttemplate;
}



if (append!= undefined) {
Resulttemplate + = append;
}

This.html (resulttemplate);

Default values for bound controls
if (this.attr ("type") = = "Select-one") {
if (dvalue!= undefined)
This.bindcontrol (Dvalue);
Else
This[0].selectedindex = 0;
}

Me.setlink ();

};


}) (JQuery);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.