Skip to content

Instantly share code, notes, and snippets.

View debugmodedotnet's full-sized avatar

Dhananjay Kumar debugmodedotnet

View GitHub Profile
var elements = document.querySelectorAll('[data-geek97-bind]');
var dbrepo = {};
elements.forEach((element) => {
if (element.type === 'text') {
var bindingProperty = element.getAttribute('data-geek97-bind');
addToScope();
element.onkeyup = () => {
dbrepo[bindingProperty] = element.value;
set: function (newvalue) {
value = newvalue;
elements.forEach(e => {
if (e.getAttribute('data-geek97-bind') === bindingProperty) {
if (e.type === 'text') {
e.value = newvalue
}
else if (!e.type) {
e.innerHTML = newvalue
}
function addToScope(){
if(!dbrepo.hasOwnProperty(bindingProperty)){
let value;
Object.defineProperty(dbrepo,bindingProperty,{
configurable:true,
enumerable:true ,
set: function(newvalue){
value = newvalue;
},
function addToScope(){
if(!dbrepo.hasOwnProperty(bindingProperty)){
let value;
Object.defineProperty(dbrepo,bindingProperty,{
configurable:true,
enumerable:true ,
set: function(newvalue){
value = newvalue;
},
var elements = document.querySelectorAll('[data-geek97-bind]');
var dbrepo = {};
elements.forEach((element)=>{
if(element.type === 'text'){
let bindingProperty = element.getAttribute('data-geek97-bind');
console.log(bindingProperty);
}
});
(function (){
console.log('Implementing two way data binding');
})();
<body>
<h2>Two-way data binding</h2>
Name: <input data-geek97-bind="name" type="text">
<span data-geek97-bind="name"> </span>
<span data-geek97-bind="name"> </span>
<script src="databinding.js"></script>
</body>
public IEnumerable<Training> GetAllTrainings()
{
return trainings;
}
[Route("Data")]
[HttpGet]
public IHttpActionResult GetData()
{
var data = GetAllTrainings();
return new TrainingDataResponse(data.ToList(), Request);
}
public class TrainingDataResponse : IHttpActionResult
{
List<Training> _data;
HttpRequestMessage _request;
public TrainingDataResponse(List<Training> data, HttpRequestMessage request)
{
_data = data;
_request = request;