E
E
Eugene2015-06-05 21:47:22
JavaScript
Eugene, 2015-06-05 21:47:22

Why is the array with "dash" in the name not processed?

Tell me this question, I get json data via Ajax, the data contains an array section with the name "total-price". All are processed normally except for it, I understood the error precisely in the presence of a dash / minus in the title.

"items": {
        "item": {
            "0": {
                "price": {
                    "name": "\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0439 \u0440\u0443\u0431\u043b\u044c",
                    "code": "RUR",
                    "rate": 1,
                    "nominal": 1,
                    "suffix": "\u0440\u0443\u0431",
                    "actual": 126
                },
                "total-price": {
                    "name": "\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0439 \u0440\u0443\u0431\u043b\u044c",
                    "code": "RUR",
                    "rate": 1,
                    "nominal": 1,
                    "suffix": "\u0440\u0443\u0431",
                    "actual": 1008,
....


$.ajax({
        url: '..... url.json',
        type: "get",
        dataType: 'json',
        async: true,
        timeout: 30000,
        success: function (data) {     
            /* для примера */
           alert(item.price.actual)    // работает
           alert(item.total-price.actual)  // не работает     
        } 
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rikcon, 2015-06-05
@atachrus

Because - (minus sign) is reserved in Javascript.
Treat like an array
item['total-price']['actual']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question