Hi guys I am looking for some help with this data-binding issue that I have with knockoutjs.
It all started when ko.applyBindings(viewModel)
was throwing me an error on one page and not others saying something to do with multiple bindings being called on the same element.
Looking at documentation I quickly fixed this issue with ko.applyBindings(viewModel, document.getElementById('ElementId'))
code.
But another problem problem has surfaced. I lost binding on edit control. In other words when I click on edit text I get a blank dialog box instead of filled one with object? properties.
Original source code - https://dnnboards.codeplex.com/
Original live demo - http://demo.dnnboards.com/
The only difference I can see is knockoutjs version. Original demo uses 2.1.0 and I am using 3.1.0 but regardless if I wrap entire demo html code in a div
<body>
<div id="myModule">...</div>
<scripts>
</body>
and change
ko.applyBindings(vm);
to
ko.applyBindings(vm, document.getElementById('myModule'));
everything still works as expected.
I couldn't get to work in jsfiddle but you should be able to get a better idea of what I was on about.
http://jsfiddle.net/iiminov/88rafcfk/
If anyone has a good suggestion of how to go about debugging this I'd much appreciate it.
But I am suspecting that
<div id="divModal" style="display:none;">
<!-- ko with: selectedCard -->
is not working correctly. Because
<!-- ko if: showAddCard -->
<a href="#" class="hlCompose" data-bind="click: $root.expandCompose">Add a card</a>
displays Add a card link on every list.
Thanks to @PW Kad the issue with jsfiddle was resolved. But that wasn't my original question/problem I was trying to solve.
As I was trying to point out after adding scope to ko.applyBindings()
I lost data-binding on dialog box but was able to solve an error with multiple bindings on the same element
.
Jsfiddles' purpose was to demonstrate that I shouldn't be having any issues. Yet I am struggling to figure out why that is the case.
However I made few observations:
self.selectedCard = ko.observable();
declarationself.selectedCard(cardToEdit);
declaration<p data-bind="with: coords">
<div id="divModal" style="display: none;" data-bind="with: selectedCard">
(this doesn't work for me btw)add a card
link/button.
with
keyword.To Do
list and in my case its present on all lists.Scratch the data binding bit with with
keyword. I found Note 1: Using “with” without a container element
which corresponds to what I am seeing in html. This is leading me to believe that not everything is ok in javascript somewhere.
<!-- ko with: outboundFlight -->
...
<!-- /ko -->
Scratch out add a card
link problem. Turns out my list items are coming back with SortOrder = 0 which causes the link to display on every list.
Well, who would have guessed that by fixing the issue with SortOrder value which not only caused add a card
link/button to be display on every list it also fixed the problem with data-binding on dialog box. Hrm...
Your fiddle was excellent in diagnosing the issue - http://jsfiddle.net/88rafcfk/1/ - there is an updated one.
It appears your code was working fine except for a single change I made - you had document.GetElementById
instead of document.getElementById
.
When I changed this everything worked fine.