Data not shown

58 views
Skip to first unread message

Daniel Duong

unread,
May 6, 2016, 1:17:13 PM5/6/16
to KnockoutJS
Hi,

I have a weird error. I have some data that is not shown on the page but that is there when I query the console. Here is the code:

            <div class="one" data-bind="visible: !uploading() && current_files().length == 1, with: current_files()[0]">
                <a data-bind="attr: file_attrs" target="_blank">
                    <span data-bind="text: file_text"></span>
                    {% if not read_only %}<i data-bind="click: $parent.remove_file, visible: !$parent.uploading()">&times;</i>{% endif %}
                </a>
            </div>

Here is what Chrome gives me:

<div class="one" data-bind="visible: !uploading() &amp;&amp; current_files().length == 1, with: current_files()[0]"></div>

Here is what I get when I query the console:

>>> manager = ko.dataFor($('.one')[0])
>>> !manager.uploading() && manager.current_files().length == 1
true
>>> manager.current_files()[0].file_attrs()
Object {href: "https://blah"}
>>> manager.current_files()[0].file_text()
"report.xlsx"

Can someone help me debug this ?

Thanks a lot !
Daniel

Gunnar Liljas

unread,
May 6, 2016, 5:30:39 PM5/6/16
to knock...@googlegroups.com
Could you try with:

<!--ko if:!uploading() && current_files().length == 1-->
<div class="one" data-bind="with: current_files()[0]">
                <a data-bind="attr: file_attrs" target="_blank">
                    <span data-bind="text: file_text"></span>
                    {% if not read_only %}<i data-bind="click: $parent.remove_file, visible: !$parent.uploading()">&times;</i>{% endif %}
                </a>
            </div>
<!--/ko-->

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Duong

unread,
May 6, 2016, 6:36:59 PM5/6/16
to KnockoutJS
Hello Gunnar,

Here is what Chrome gives me now:

<!--ko if:!uploading() && current_files().length == 1-->
<!--/ko-->

Again, what I get on the console:

>>> manager = ko.dataFor($('#file_upload_sub_bindings')[0])
>>> !manager.uploading() && manager.current_files().length == 1
true

Thanks for your help,
Daniel

Peter Shaw

unread,
May 19, 2016, 12:27:34 PM5/19/16
to KnockoutJS
Hi Daniel,

First thing I would do would be to just remove the inner code, and concentrate on the visible binding itself and nothing else.

I'd do this by validating that my visible binding worked, just by using the following:

            <div class="one" data-bind="visible: !uploading() && current_files().length == 1">
<p>I worked</p>
            </div>

If that works, then add your "with" binding back on and see what happens.

Personally I suspect the "with" binding, I've certainly had problems in the past, and from prior experience I've nearly always had to make sure a "with" binding is on it's own element with no other bindings, it just never seems to play nice with other bindings on the same element.

If you add the "with" binding back on, and it fails to show the P tag, then try nesting a separate div inside with the P inside of that and see where that gets you.

Regards
Shawty

noirabys

unread,
Jun 9, 2016, 5:03:46 AM6/9/16
to KnockoutJS
hi,
sometimes weired stuff happens if the html tree is not valid or wrong balanced 
the browser fixes it without error or warning resulting in unexpected behaviour
perhaps the problem is outside of the given code ..

best regards,
 noirabys
Reply all
Reply to author
Forward
0 new messages