Hello and thank you for your time :) My first post here, but I always end up here when im researching so I figured why no开发者_如何学Ct.
I would like to turn this:
{"label":"112","value":"airbrush tanning,airbrush tan"};
Into this:
{"label":"112","value":"airbrush tanning"}, {"label":"112","value": "airbrush tan"}
I was thinking about using .split() to catch each comma delimited value. But passing both into a new array is escaping me for some reason. I am not sure what method will handle this so im hoping someone will be kind enough to point me in the right direction.
Thank you again for your time.
var obj = {"label":"112","value":"airbrush tanning,airbrush tan"};
var array = $.map(obj.value.split(","), function(value) {
return {label: obj.label, value: value};
});
console.log(array);
http://jsfiddle.net/Aj7qF/1/
Output:
[Object { label="112", value="airbrush tanning"}, Object { label="112", value="airbrush tan"}]
精彩评论