if index > 0: loop; else: do only once (JSON & jQuery) -
I am optimizing something on this jQuery paging script I
I have found paging well , And it is controlling different Javascript responses correctly.
I have a problem though. The response is that JSON is expected to keep an index / arrame.
90% of the time, in my JSON I have several entries, but sometimes I only return one item, this is the result in zero entries.
Here I have the code
var pagedContent = {data: blank, holder: empty, current index: 0, init: function (data, holder) {jQuery ( "Body") data (holder, data). This. Holder = holder; this. Show (0, holder); // show last}, show: function (index, holder) {this.data = jQuery ("body"). Data (holder); If (! This.data) {return; } Var j = 2; If (this.data.length- index & amp; lt; = j) {j = this.data.length-index-1; } Var jsonObj = this.data [index]; If (JsonObj) {return; } Var holdSubset = ""; For (i = 0; i & amp; lt; = j; i ++) {jsonObj = this.data [index + i]; This.currentIndex = Index; If (this.holder == "id1") {var theResultVariables = jsonObj.whatever var results in input = '& amp; ;; Div class = "putstuff" & gt; + TheResultVariables + & amp; Lt; / Div & gt; '; } If (this.holder == "id2") {var theResultVariables = jsonObj.whatever var results in input = '& amp; ;; Div class = "putstuff2" & gt; + TheResultVariables + & amp; Lt; / Div & gt; '; } Hold Subset = Hold Subset + resultInput; HTML ("body") HTML ("& IDE id = \" counter \ "& amp; g; + + ParsefLat (index + 1) +" to "+ parseflot (index + j + 1) +" + + This.data.length + "& amp; amp; lift; / div>" + + + HoldSubset + "& amp; lt; div class = \" predecessor \ "and & gt; & amp; lt; / div Click here (this.previoushandler). Data ("& amp; amp; lt; prev"). Data ("jellist", this. Holder). Data ("this index", index - 2-1); .JQuery ("body") attached (last) ;} If (index S + i & amp; lt; this.data.length) {var next = jQuery ("& a class = \" next \ "and"; "). Attr ("href", "#"). Click (this.nexthandler) .text ("Next & amp; ;;) Data (" Joelist ", this.holder). Data (" This Index, Index + 2 +1); . JQuery ("body") enclosed (next); }}, Nexthandler: function () {pagedContent.show (jQuery (this) .data ("this index"), jquery (this) .data ("johlist")); return false; }, Previous Handler: Function () {pagedContent.show (jQuery). Data ("this index"), jQuery (this) .data ("jellist"); return false } };
I know that I can add another check
var jsonObj = this.data [index]; If (! JsonObj) {var jsonObj = this.data; } If (JsonObj) {return; }
and then lower below
jsonObj = this.data [index + i]; If (JsonObj) {jsonObj = this.data; }
But I do not think that is probably the most effective way of doing this. Any ideas?
Since you are using jQuery, . It takes an array or a scalar, and gives an array. If you add a call as a preceding step in this way:
this.data = jQuery.makeArray (this.data);
You do not have to worry about whether it is a scalar or an array. Scales will be converted into arrays of 1.
Comments
Post a Comment