JSFiddle - React, Tailwind, and code Playground
by David Kyle
HTML
<div>
<label for="PageSize">Page Size:</label>
<input id="PageSize" name="PageSize" type="text" />
</div>
<div>
<label for="Attachment">Include Attachment:</label>
<input id="Attachment" name="Attachment" type="text" />
</div>
JavaScript
let keys = {};
var data = [{
Name: 'DefaultPageSearchSize',
Value: 10
},
{
Name: 'CommunicationPlanDefaultAttachment',
Value: false
}
]
function process() {
Object.keys(keys).forEach(function(key) {
console.log(key);
var potentialData = data.filter(function(element) {
return element.Name === key;
})[0];
if (potentialData) {
keys[key]($(document), potentialData);
} else {
console.log('No data match');
}
});
}
function setKeys(options) {
keys = options;
}
setKeys({
'DefaultPageSearchSize': function($dom, data) {
console.log('here');
$dom.find("#PageSize").val(data.Value);
},
'CommunicationPlanDefaultAttachment': function($dom, data) {
$dom.find("#Attachment").val(data.Value);
}
});
process();