Sunday 15 September 2013

javascript - Detecting if array object is "in use" -


I have some scripts that are calling AJAX information from a server and then displays information to the block on the page. And every 8 seconds these blocks will be faded up to a new set of information.

The information given to the server is placed in a fixed line which pushes new items every 8 seconds.

And for each block, I got a random object from that array to show it to me. The only thing is that there are many duplicates in my block.

Is there a way to check and see that array object has been told from any other block, and if so, it will move forward to find another object.

  var queue = fixed queue (50); $ (Document) .ready (function () {$ ('. Submit') Click (function () {setInterval (function () {queue.push (fulltweet);}, 8000);});}); SetInterval (function () {randotime = intervals [Math.floor (Math.random (* * * intervals.length)] $ $ ('block1', '.photo1: nth-child (1)'). Work ($ {This} .hide (); $ (this) .html (Q [0]); $ (this) .Fed In (2000); $ (this) .Delay (Random); $ (this). Dequeue ();}); $ ('block1', '.photo1: nth-child (1)'). Fadeaut (2000);}, random);   

I was making a random number based on the length of the queue and was calling queue [rando] to call it, but again, I'm getting duplicates in blocks.

most First, if you do not want duplicate items in your array, then duplicate them before controlling new items in your array, control whether it is present in your array or not. If you type primitive type (string, integer, etc.) ), Then the equality operation can not be used. Therefore you need to check a function, if any element element is inserted into the array before the inclusion. Is not present, and this function should use the same function that compares two given object.

Second, Javascript allows you to add fields to objects in runtime. So when a block reaches an object and displays it, you can put the field on this object. Let's say its name is 'information'.

When the block reaches the object:

  object.inuse = true;   

Block B reaches the same object randomly:

  var object = pick-random (); While (object.inuse) {object = pickrandomly (); } // Here is a unique item not used by any other block.   

I hope that helps if you can provide a sample code, then I can provide a better answer.

No comments:

Post a Comment