inherit
172351
0
Sept 5, 2019 10:56:35 GMT -8
DarkPikachu
Complexity == Fun
320
October 2011
tcll
|
Post by DarkPikachu on Jun 18, 2014 7:36:57 GMT -8
$(document).ready(function() { var features = pb.plugin.get('plugin_name').settings.checkboxes; for (var i=0; i<features.length; i++) { var feature = features[i]; switch (feature) { case "checkbox_value1": //do something here case "checkbox_value2": //do something else here }; }; };
when I figured this out, I was hoping for something more efficient such as: if (features.checkbox_value1.checked()) {};
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jun 19, 2014 23:58:05 GMT -8
Since the selected checkboxes are returned in an array of the values assigned to each checkbox (e.g. "checkbox_value2" in your given example) then if all you want is some way to return a boolean if a specific checkbox value is present in that array rather than iterate through the array you can use $.inArray.
if($.inArray("checkbox_value4",features) != -1){ //do something here }
JQuery as it always does will first try using a native browser equivalent (Array.prototype.indexOf) if supported because a native solution is always faster than any javascript implementation, then only fallback to a pure javascript solution if not supported. Keep in mind however that this method does perform type matching as well so 1 === "1" would be false. If you encounter such a situation you can first cast to a known type or use the $.inArrayLoose method which I believe was added by the Proboards framework (not part of a jquery release)
|
|