How to integrate an dynamically generated JSON Object into an other object?

Posted by Marco Ciarfaglia on Stack Overflow See other posts from Stack Overflow or by Marco Ciarfaglia
Published on 2012-09-25T15:31:30Z Indexed on 2012/09/25 15:37 UTC
Read the original article Hit count: 242

Filed under:
|

How can I put this JSON Object in the function or object below?

// this function generates an JSON Object dynamically       
$(".n_ListTitle").each(function(i, v) {
            var node = $(this);
            var nodeParent = node.parent();
            var nodeText = node.text();
            var nodePrice = node.siblings('.n_ListPrice');

            var prodPrice = $(nodePrice).text();
            var prodId = nodeParent.attr('id').replace('ric', '');
            var prodTitle = nodeText;

            var json = {
                id : prodId,
                price : prodPrice,
                currency : "CHF",
                name : prodTitle
            };
            return json;
        });

        TDConf.Config = {
        products : [
    // here should be inserted the JSON Object
        {id: "[product-id1]", price:"[price1]", currency:"[currency1]", name:"[product-name1]"},
        {id: "[product-id2]", price:"[price2]", currency:"[currency2]", name:"[product-name2]"},
        ...

        })],
        containerTagId :"..."
        };

If it is not understandable please ask :) Thanks in advance for helping me to figure out!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery