Today in two development time, see the source code of news list is Aajax get, click News content trigger Edit, I did not see the news ID but can find information.
While watching the $.ajax traversal assignment, $TR ("<a> News content </a>"). Data ("Data", "obj") binds the JSON data of this news, as long as $.data ("Data") is available for this array when editing
1. Basic syntax for $data
Data ([Key],[value])
Stores or reads data on an element, returning a jquery object.
When the parameter has only one key, the value corresponding to the key stored in the DOM is read by the jquery object, and it is worth noting that if the browser supports HTML5, it can also read the values stored in the DOM using data-[key] = [value]. See the last example.
When the parameter is two, the data for the Key-value key-value pair is stored in the DOM corresponding to the jquery object.
If the jquery collection points to multiple elements, the corresponding data is set on all elements. Instead of creating a new expando, this function can store data in any format on an element, not just a string.
V1.4.3 new usage, data (obj) can be passed in the form of Key-value.
Instance of 2.$.data
2.1
Storing data on a div:<div><div>
jquery code;
$("Div"). Data ("blah");//undefined$("Div"). Data ("blah","Hello");//blah set to Hello$("Div"). Data ("blah");//Hello$("Div"). Data ("blah", the);//set to$("Div"). Data ("blah");// the$("Div"). Removedata ("blah");//Remove blah$("Div"). Data ("blah");//undefined
2.2
Save the name/value pair data on a div:<div><div>
jquery code;
$("Div"). Data ("Test", {first: -, Last:"pizza!" });$("Div"). Data ("Test"). First//;$("Div"). Data ("Test"). Last//pizza!;
3. I have seen
Assignment value:
$.each (data, function (n, obj) {console.log (obj); if(Currentstatus = ="Mreg") { //Fillreg (obj);$("#task-table"). Append ("<tr class= ' Mreg ' ><th></th><th>"+ Obj.t.time +"</th><th colspan= ' 3 ' >"+ Obj.t.rate +"%</th><th colspan= ' 2 ' >"+ Obj.t.worktime +"</th></tr>"); $.each (obj.lt, function (n, data) {//console.log (data); varTR = $ ("<tr><th>"+ (n +1) +"</th><th ><a href= ' # ' onclick= ' Edittask (this) ' >"+ Data.content +"</a></th><th>"+ Data.rate +"</th><th>"+ Data.project +"</th><th>"+ Data.category +"</th><th>"+ Data.worktime +"</th><th>"+ Data.endtimesta +"</th></tr>"); Tr.find ("a"). Data ("Data", data); ------------Focus $ ("#task-table"). Append (tr); }) } Else{Fillcou (obj); } });
Edit:
varEdittask =function (sender) {varobj = $ (sender). Data ("Data"); //Get task InformationCurrentID =obj.id; $('#content'). Val (obj.content); $('#project'). Val (Obj.project); $('#category'). Val (obj.category); $("#worktime"). Val (obj.worktime); $("#endtime"). Val (obj.endtime); $("#rateO"). Val (obj.rate); $("#rateO"). Text (obj.rate+"%"); }
$.data (data, "")