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);