JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://dev.sencha.com/deploy/ext-4.0.0/ext-all-debug.js"></script>
<link rel="stylesheet" href="http://dev.sencha.com/deploy/ext-4.0.0/resources/css/ext-all.css">
JavaScript
Ext.onReady(function(){
Ext.define('EAM.utils.Utils', {
alternateClassName: 'EAM.Utils',
statics: {
/**
* Checks a JSON object if a certain property exists.
*
* Usage:
*
* var obj = {
* me: {
* life: {answer: 42},
* universe: {answer: 42},
* everything: {answer: 42}
* }
* };
* console.log(EAM.Utils.propertyExists(obj, 'me.life.answer')); //returns true
* console.log(EAM.Utils.propertyExists(obj, 'me.universe.answer')); //returns true
* console.log(EAM.Utils.propertyExists(obj, 'me.life.question')); //returns false
* console.log(EAM.Utils.propertyExists(obj, 'property.im.not.sure.exists')); //returns false
*
* @param {Object} obj - The JSON Object to iterate over to look for the property.
* @param {String} property - The property that needs to be found.
* @return {Boolean} true if the property is found, false otherwise
*/
propertyExists: function(obj, property) {
if (Ext.isEmpty(property) || Ext.isEmpty(obj)) {
return false;
}
var props = property.split('.'),
count,
prop;
for (count = 0, len = props.length; count < len; count++) {
prop = props[count];
if (Ext.isObject(obj) && obj.hasOwnProperty(prop)) {
obj = obj[prop];
} else {
return false;
}
}
return true;
}
}
});
myPanel = Ext.create('Ext.panel.Panel', {
title: 'Test',
html: '',
height: 200,
renderTo: document.body
});
var obj = {
me: {
life: {answer: 42},
universe: {answer: 42},
everything: {answer: 42}
...