Last active
November 22, 2018 19:34
-
-
Save danielbonifacio/85351f88f560eae4ea6c1a29ddf59ee3 to your computer and use it in GitHub Desktop.
ajuda com objetos recursivos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
const FORMS = $('[valor=form]'); | |
const data = {}; | |
/** | |
* TODO: FAZER ESSE TREM CRIAR OBJETO SOZIN | |
* teste começa aqui | |
*/ | |
let test = {}; | |
const createCustomObject = (arr) => { | |
const object = arr.pop(); | |
test = { test, object }; | |
console.log(test); | |
if (arr.length > 0) { | |
createCustomObject(arr); | |
} | |
}; | |
createCustomObject(['a', 'b', 'c']); | |
console.log(test); | |
/** | |
* teste termina aqui | |
* daqui pra baixo tudo ta OK (eu espero) | |
*/ | |
const setData = (form) => { | |
const formData = {}; | |
$(form).find('input:not([type=submit])').each((index, input) => { | |
const { name, value } = input; | |
formData[name] = value || null; | |
}); | |
return formData; | |
}; | |
const registerSubmit = (form) => { | |
const submit = (e) => { | |
e.preventDefault(); | |
const { id } = e.target; | |
}; | |
$(form).on('submit', submit); | |
}; | |
const registerReactivity = (form) => { | |
const reactivity = (e) => { | |
const { name, value } = e.target; | |
data[form.id][name] = value; | |
}; | |
$(form).find('input:not([type=submit])').on('keyup change', reactivity); | |
}; | |
const registerData = (index, form) => { | |
data[form.id] = setData(form); | |
registerSubmit(form); | |
registerReactivity(form); | |
// console.log(data); | |
}; | |
FORMS.each(registerData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment