There probably is a solution to your problem, but you’ll just hit another one later on that is close enough that you’ll try to reuse this solution, but not quite close enough for it to really work. So you’ll end up writing a layer of abstraction that will deal with more general cases. At which point you will have effectively written a portion of your own framework.
If you’re anything like me, at this point you will take a good long look in the mirror and decide that it is probably a far better use of everybody’s time and effort to study an existing framework. I picked Angular.
Incidentally, using Angular, what you ask is incredibly simple. See chapter 4 of the Tour of Heroes for how one would write this.