JS Fast completion of database data display 2

Source: Internet
Author: User

Knowledge point 1: What is the difference between HttpResponse and jsonresponse?

HttpResponse (Json.dumps (dictionary or list))

Jsonresponse (only a dictionary, not a list!) ), if you want to write the list, then add the attribute safe------>jsonresponse (list, safe=false)

jquery extensions are available in two ways:

Way One:
Jquery.extend ({ "xxx": function (args) { alert (args) }}) $.xxx (666)

Way two:
Jquery.fn.extend ({
"XXX": function (args) {
Contains the statement about this;
}
})

$ ("#id"). XXX (666) //This call is not jquery, but a specific tag, and the above refers to the tag of the call.

The use of self-executing functions:

(The function (JQ) {
Function F1 () {}
function F2 () {}
...
Jq.extend ({
"XXX". function (args) {}
})
}) (JQuery)

$.XXX (666)

This section focuses on:

1. Because JS does not have a format function in Python, then you need to write it yourself.

Because JS has a string replace the built-in function replace, use: String S.replace ("s substring", "to do the substitution of the string"), in fact, the formatting of the string is the essence of the string substitution.

    

var name = ' Alexegon '= name.replace (' e ', ' EEE ');
Result: New_name:aleeexegon, will only replace the first place!!!
Mode 2:
The first parameter of the Repalce is written as a regular expression, and the format is/regular expression/, if this is also the first place to replace, if you add g later, it is replaced by all conforming regular expression specification.
That is, new_name = name.replace (/Regular expression/g, ' EEE '), the result is: Aleeexeeegon.
Mode 3:
The second parameter of replace can also be an anonymous function and must have a return value, then the return value replaces the string that the regular expression matches successfully.

Name.replace (/a/,function (k,v) {})
where k----> refers to a successful string, V-----> refers to the position of this string
Note: The value of k,v can have multiple groups.
Formatting:
Name = "Sfsdcdsvd{xxx},vfes{uuuu}"
Kwargs = {"xxx": ' Alex ', ' uuuu ': ' 18 '}
Need to write a format function to make Name.format (Kwargs)

JS Prototype: Adds a method to the class, which can be called later, and automatically calls the following function when the string object calls format.
String.prototype.format = function (Kwargs) {
Return This.replace (/\{(/w+) \}/,function (k,v) {
return KWARGS[V]
});
}
  
Name.format (Kwargs);

JS defines the class:
function Foo (name,age) {
THIS.name = name;
This.age = age;
}
Foo.prototype.func = function () {
This ...
}
obj = new Foo (' Egon ', 19);
Obj.func ()



    

JS Fast completion of database data display 2

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.