سؤال

I would like to use a variable (string) as part of my JSON target. Instead of simply coding for each section, like this:

$.each(data.portfolioitems.section1, function (k,v){...}
$.each(data.portfolioitems.section2, function (k,v){...}
$.each(data.portfolioitems.section3, function (k,v){...}

I would like to have a variable "varsection" that indicates which section should be called, like this:

$.each(data.portfolioitems.varsection, function (k,v){...}

As this exists, it seems that I am attempting to target the section "varsection", which of course doesn't exist.

I have found other topics where it was discussed how to use a variable as part of a JSON target, but it seems that none of the solutions I found are acceptable for this scenario where the target is an argument.

هل كانت مفيدة؟

المحلول

data.portfolioitems[varsection]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top