简体   繁体   中英

getting value from key as id name

I am waiting for a number from server, once I get the number, I want to find an according id name to change the background of that div.

So, I created a set of key and value

var timelineKeys = {
        "4": "btn_no_1",
        "5": "btn-no-2",
        "6": "btn-no-3",
        "7": "btn-no-4",
        "1": "btn-no-5",
        "2": "btn-no-6",
        "2": "btn-no-7",
    }

in my $.ajax, I get the variable from server and I call it 't', 't' will be one of the key numbers there, but how can I get text "btn-no-.." dynamically using this variable? timelineKeys.t seems doesn't work.

Thanks

timelinekeys[t]

is the syntax when the property name you want to access is contained in a variable, t in your case; for more information refer to this question: Difference between using bracket (`[]`) and dot (`.`) notation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM