javascript - immutablejs : find if map contains key value -


i trying determine whether or not part of immutable map contains key value, checked: true, , if so, set checked: true on upper level. object looking on looks so:

const memo = {   "topics": {     "filters": {       "psychological disorders": {         "filters": {           "anxiety disorders": {             "filters": {},             "checked": true <-- check value @ level           }         }       }     },     "isopen": false   } } 

note: data immutable.

so after function ran change :

const memo = {       "topics": {         "filters": {           "psychological disorders": {             "checked": true, <-- check true added             "filters": {               "anxiety disorders": {                 "filters": {},                 "checked": true                }             }           }         },         "isopen": false       }     } 

the var have access right "topics" name, trying find out if topics -> filters -> filters has checked: true inside it. initially, trying tojs() memo , check inside lodash.

something :

_.find(memo['topics'], _.flow(     _.property('filters'),     _.property('filters'),     _.partialright(_.any, { checked: true }) )); 

i can use information modify object, wondering if possible achieve without taking out of immutable. far have tried :

   const namecheck = 'topics';     const hascheckedfilters = memo.update(namecheck, map(),         (oldresult) => oldresult.update('filters', map(),                (oldsection) => {                 // filters inside object has checked : true, .set('checked', true);                 const fromimmutable = oldsection.tojs();                 const checkforchecked = _.find(fromimmutable.filters, {checked:true});                if(checkforchecked) {                    oldsectsion.set('checked', true);                }                }             )         )     ); 

this not seem work because not looping on filters. appreciate input, thanks!

this keeps data immutable. looping through each property in topics.filters, checking if property has filters key. if loop through that. if checked true in subitem set checked true in parent item , return new map.

const memo = {       "topics": {         "filters": {           "psychological disorders": {             "checked": false,             "filters": {               "anxiety disorders": {                 "filters": {},                 "checked": true                }             }           }         },         "isopen": false       }     };  let map = immutable.fromjs(memo);  map.getin(['topics','filters']).foreach((item, i) => {   if(item.has('filters')){     item.get('filters').foreach(subitem => {       if(subitem.get('checked') === true){         map = map.setin(['topics', 'filters', i], item.set('checked', true));        }     });     } });  console.log(json.stringify(map.tojs())); 

http://jsbin.com/gorohewuji/edit?js,console


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -