user1234
user1234

Reputation: 3159

How to add commas between 2 span elements created dynamically

Im trying to add a delimited between my 2 <span> elements. here is my code:

mRender: function (data, type, obj) {
                var returnVal = "";
                _.each(obj.qaccess, function(item, index){

                    returnVal += "<span class='_product'>" + item["product"] + "</span>";

                });
                return returnVal;
            }

The obj.qaccess returns this:

postalCode: "95035"
qaccess: [{product:aa, status:enabled, roleIdentifiers:[], permissionIdentifiers:[]},…]
    0: {product:aa, status:enabled, roleIdentifiers:[], permissionIdentifiers:[]}
    permissionIdentifiers: []
    product: "aa"
    roleIdentifiers: []
    status: "enabled"
    1: {product:bb, status:Active, roleIdentifiers:[], permissionIdentifiers:[]}
    permissionIdentifiers: []
    product: "bb"
    roleIdentifiers: []
    status: "Active"
sfAccountId: null

im trying yo get the item['product'] value in the span element. if there are more than two values for the 'product', im looking to separate them with a comma.

Any ideas how can i achieve this?

Upvotes: 0

Views: 187

Answers (1)

Guffa
Guffa

Reputation: 700372

Put the texts in an array, and join them with a comma:

mRender: function (data, type, obj) {
            var returnVal = [];
            _.each(obj.qaccess, function(item, index){

                returnVal.push("<span class='_product'>" + item["product"] + "</span>");

            });
            return returnVal.join(', ');
        }

(I used a comma and a space between the items, that usually looks good.)

Upvotes: 1

Related Questions