Analysis of Ajax webshop DatasetAnd dbcontrolData sensing mechanism
Implementation PrincipleBy registering the data Sensor Object List, all registered data sensor objects are notified when a corresponding event occurs in dataset. When a data Sensor Object receives a notification, it is notified Based on the message number and data, for example, refresh and display.Message numberModify: 12 open: 0 Refresh: 5 close: 7 move record: 3 append: 1 Delete: 2 firedatachange: 6 post: 13 cancel: 9 apply: 8 fieldvalue firechange: 4 notify lookup Dataset: 11Program AnalysisTake dbedit as an example. First, dbedit sets the property dataset or setdataset and calls linkobj to register dbedit to the data Sensor Object List. This list is actually an array. When a dataset event occurs, call notify to notify all objects in the Data Sensor Object List, and all data sensor objects have an interface to implement handlemessage, which is called in dataset. Let's take a look at notify's implementation:
Dataset. Prototype. Y = function (Act, recno, p) {var OS = This. linkobjs; If (! OS | this. autocontrol = false) return; For (var j = 0; j <OS. length; j ++) if (OS [J]. handlemessage) OS [J]. handlemessage (this, act, recno, P );} |
Then let's take a look at what dbedit's handlemessage has done. See the following implementation. It's nothing more than refreshing the display data.
Function dc_handlemessage (sender, MSG, recno) {If (MSG! = 6 & MSG! = 12) This. refresh ();} function dc_refresh () {var V, F; If (this. dataset. active) {f = This. dataset. fields. field [this. datafield]; If (! F) jcl_err (this. name + '. datafield: '+ this. datafield + err_nofield); If (f) {This. readonly = f. readonly; V = f. getvalue (); If (V = NULL) V = ''; this. value = V; If (this. type = 'span ') This. innerhtml = V; // dblabel if (this. type = 'checkbox') {If (this. checkedvalue = V) {This. checked = true; this. defaultchecked = true;} else {This. checked = false ;}}} else {This. value = ''; If (this. type = 'span ') This. innerhtml = ''; // dblabel }} |