I'm currently populating some elements with json. However if a new json is loaded. the json looks slightly different. How can I ignore the first part of the key so that it works. I was thinking I could use an asterisk but that gives me a error in firebug.
Here is my jQuery
var items = [];
$.each(data[0].attributes['*.dyn.prop.current.profile'], function (key, val) {
items.push(val);
});
displaySortLabel(items, "type-details");
Example JSON 1
[
{
"avatarDefinitionId":1,
"avatarName":"edge",
"attributes":{
"examplePrefixToSkipOver.act.halt":"1",
"examplePrefixToSkipOver.dyn.prop.current.profile":"1",
"examplePrefixToSkipOver.dyn.prop.firmware":"1.0",
"examplePrefixToSkipOver.dyn.prop.ip.address.3g":"192.168.1.1",
"examplePrefixToSkipOver.dyn.prop.ip.address.cloud.com":"192.168.1.1",
"examplePrefixToSkipOver.dyn.prop.ip.address.lan":"10.0.0.1",
"examplePrefixToSkipOver.dyn.prop.ip.address.wifi":"192.168.1.1",
"examplePrefixToSkipOver.dyn.prop.location":"Chicago Office",
"examplePrefixToSkipOver.dyn.prop.name":"examplePrefixToSkipOver",
"examplePrefixToSkipOver.dyn.prop.priority":"1",
"examplePrefixToSkipOver.dyn.prop.status.detail":"Placeholder-Text",
"examplePrefixToSkipOver.dyn.prop.timestamp":"2010-01-01T12:00:00Z"
}
}
]
You can use a for
loop:
for ( key in data[0].attributes ) {
if (key.match('.dyn.prop.firmware')) {
items.push(data[0].attributes[key]);
}
}
http://jsfiddle.net/cSF5w/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With