Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created November 11, 2015 20:15
Show Gist options
  • Save Sigmus/0954938aa9457665314b to your computer and use it in GitHub Desktop.
Save Sigmus/0954938aa9457665314b to your computer and use it in GitHub Desktop.
// clica em cor, motor ou opcional
// altera objeto dude e manda
// gerar urls de todas as imagens
// de novo
var dude = {
color: 296,
version: 'longitude',
engine: 100,
opcionais: [
{code: '430', selected: true},
{code: '230', selected: false},
{code: '6JC', selected: true},
{code: '85J', selected: false}
]
};
function selectCode(code, value) {
var opcional = dude.opcionais.filter(function(item) {
return item.code == code;
})[0];
opcional.selected = value;
logDude();
}
function getSelectedCodes() {
return dude.opcionais.filter(function(item) {
return item.selected;
}).map(function(_item) {
return _item.code;
});
}
function logDude() {
console.log(JSON.stringify(dude, null, 4));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment