In addition to table binding, other cyclic lists need to be bound.
In fact, they all use templates as data. The method for saving the template is only one way to annotate it. Better methods can be used freely. This is to obtain the template. For example, you can use a JSON file to store the required template and then place it in a templates. JSON data is generated in JS or templates configured by XML. If you need to use the template directly. tempname is enough. It is too tired to write a blog. Especially when you share your thoughts with others. I will not go into details here. Paste the code
; (Function ($ ){
VaR templatelist = []; // stores the list of general 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 value of the bound control
If (this. ATTR ("type") = "select-one "){
If (dvalue! = Undefined)
This. bindcontrol (dvalue );
Else
This [0]. selectedindex = 0;
}
Me. setlink ();
};
}) (Jquery );