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
| 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; |
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
| 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 | |
| } |
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
| function addToScope(){ | |
| if(!dbrepo.hasOwnProperty(bindingProperty)){ | |
| let value; | |
| Object.defineProperty(dbrepo,bindingProperty,{ | |
| configurable:true, | |
| enumerable:true , | |
| set: function(newvalue){ | |
| value = newvalue; | |
| }, |
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
| function addToScope(){ | |
| if(!dbrepo.hasOwnProperty(bindingProperty)){ | |
| let value; | |
| Object.defineProperty(dbrepo,bindingProperty,{ | |
| configurable:true, | |
| enumerable:true , | |
| set: function(newvalue){ | |
| value = newvalue; | |
| }, |
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
| 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); | |
| } | |
| }); |
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
| (function (){ | |
| console.log('Implementing two way data binding'); | |
| })(); |
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
| <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> |
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
| public IEnumerable<Training> GetAllTrainings() | |
| { | |
| return trainings; | |
| } |
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
| [Route("Data")] | |
| [HttpGet] | |
| public IHttpActionResult GetData() | |
| { | |
| var data = GetAllTrainings(); | |
| return new TrainingDataResponse(data.ToList(), Request); | |
| } |
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
| public class TrainingDataResponse : IHttpActionResult | |
| { | |
| List<Training> _data; | |
| HttpRequestMessage _request; | |
| public TrainingDataResponse(List<Training> data, HttpRequestMessage request) | |
| { | |
| _data = data; | |
| _request = request; |