JQuery.each () broken in BB OS5?

I worked on debugging some jQuery on a BlackBerry OS5 device (8530). There are a number of problems, but the one I narrowed down is related to jQuery .each()

The logic is this:

 $objectArray.each(function(){ alert('test'); if(...some logic...){ $(this).addClass('testClass'); }; }) 

In any normal browser, I get a warning, then OK, and then I see that this particular element (in this case TD) gets an updated class if the logical operator is true. Then it repeats the rest of the elements, each of which receives a warning, me OK, and I see that this TD class is being updated.

In the BlackBery 8530, however, I get every warning, but TDs are not updated one by one. Instead, they are all updated immediately after the last warning, based only on the logic of the last TD.

There are likely to be serious JS issues with this particular browser, but I am wondering if there is a way around this. Are there alternatives to using .each() in jQuery?

UPDATE:

More detailed code example:

 $TRs.each(function(){ var $TR = $(this); var $checkBoxTD = $TR.find('td.td3'); var $checkBox = $checkBoxTD.find('input'); alert($checkBox.is(':checked')); if ($checkBox.is(':checked')!=true){ $checkBoxTD.addClass('notSelected'); } }); 

I look at every TR table. Inside each TR there is a TD (.td3) that contains a flag. I need to check everyone. If it is not installed, I need to add a class to TD.

In good browsers, a warning will show true or false, and based on this particular warning, you will see that the class is applied appropriately to this line when the warning is turned off. Then it is repeated for each row.

In the BB OS5 browser, each warning appears with the correct value, but the classes are not updated AFTER the most recent warning / cycle, so each TD class used only the logic of the last cycle.

UPDATE 2 (fix?):

Thanks to Alex, I did a little more playing with this and found a way to get this working in a stubborn browser.

 $TRs.each(function(idx){ var $TR = $(this); var $checkBoxTD = $TR.find('td.td3'); var $checkBox = $checkBoxTD.find('input'); alert($checkBox.is(':checked')); if ($checkBox.is(':checked')!=true){ $TRs.eq(idx).find('td.td3').addClass('notSelected'); // <-- the 'fix' } }); 

The difference is that I return to the main jQuery $ TR object and, in particular, grab one of the elements from it based on its index.

So my last question is: does the above solution have any disadvantages for “good” browsers? Is there any success?

+6
source share
1 answer

Try the following:

 $objectArray.each(function(idx, element){ alert('test'); if(...some logic...){ $(element).addClass('testClass'); }; }) 

UPDATE:

Try this, maybe it has less overhead ...

 var $checkBox = $TRs.find('td.td3 input:not(:checked)'); $checkBox.each(function(){ $(this).parent().addClass('notSelected'); }); 
+2
source

Source: https://habr.com/ru/post/894058/


All Articles