Looking for an expert to help troubleshoot function issue

148 views
Skip to first unread message

Sherwin Gaddis

unread,
May 27, 2021, 11:02:13 AM5/27/21
to KnockoutJS
I have already posted the issue on stack overflow.
So here is the link to the issue at hand.


I have been working on this for a couple of week with no real resolution. I have read over the over the documentation and nothing leads to a solution that fits what I am working with. If you are an expert and know a solution please contact me. '

SLG

unread,
May 27, 2021, 12:32:41 PM5/27/21
to KnockoutJS
Not seeing the whole code base, based on the screen shot, the regDate should show up on the right side.

patient_data_view_model is a standard way in Knockout to define a view model.

it should be used in new keyword. so check everywhere the partient_data_view_model is referrenced

Another possibility if the object is created view the mapping plugin.
if the property is not in the include properties list and it is null. 
The mapping plugin will not create that property.

Knockout is a very elegant simply library, there should not be too difficult to find the cause of the issue.

Sherwin Gaddis

unread,
May 27, 2021, 12:58:16 PM5/27/21
to knock...@googlegroups.com
Thank you for replying so quickly.

Here are all the files to do with the codebase. My apologies for not including them sooner.
The function setMyPatient builds the data that is being passed into the knockoutjs.




I have searched the codebase looking for mappings of the objects and have found nothing. 

I really appreciate your insight.



Juggernaut Systems Express


--
You received this message because you are subscribed to a topic in the Google Groups "KnockoutJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/knockoutjs/gODM6DXcfeE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to knockoutjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/knockoutjs/1e60f1b9-7513-4c3b-a2d5-7ee5c7b0f918n%40googlegroups.com.

SLG

unread,
May 27, 2021, 2:10:10 PM5/27/21
to KnockoutJS
Don't see any obvious issue after a quick look at the source code 
Adding the observable to the patient_data_view_model like you said should add the property to the object.

one way you can track the change is to add the console.log (self) right before the return this line

    });

    console.log(this);

    return this;
}


in this case, you can see the patient data view model across the life time.

This might be able to provide some hint on when the regdata disappears from the object.

Sylvain Garden

unread,
May 28, 2021, 5:55:54 AM5/28/21
to KnockoutJS
Open the debugger, open the javascript source file. Chance your code modification is not here, meaning you don't actually test what you think (it happens to everyone). With such a php/js mix, be careful with cache issues.

If you see your code change, set a breakpoint inside the constructor. Check that your modified constructor is indeed called. Chance your code is actually dead code, and another version of the constructor is called.

if your modified constructor is indeed called, check the new object is indeed the object used. Chance your object has been actually mapped to another object copy by some framework (backbone?) and that you have to change some declarative code about this mapping.

To check the object displayed by the view (HTML) is the object created by your modified constructor, type "o = this" in the console while paused on the constructor breakpoint. Then compare o with the object within the datamode:
o === ko.dataFor(document.body).path.to.the.viewmodel.with.parenthesis().if.observable().involved() should return true.

The browser plugin is almost useless. Here is what you can type in the console instead:
ko.dataFor($0) or ko.contextFor($0).$data returns the datamodel for the selected DOM element
ko.contextFor($0) returns the whole "context" which contains even more information).
ko.dataFor(document.body) will return the root viewmodel

I wish you luck.

Sherwin Gaddis

unread,
May 28, 2021, 6:55:20 AM5/28/21
to knock...@googlegroups.com
Sylvain,
Thanks for the advice. I think you are right that the code is being called from somewhere else. I have not been able to find where it is being called from. I put in the console.log and it produced nothing. So, it is dead code. I broke down and decided to go a different route. Sometimes you just can't use the construct that is there. Thanks for all your advice.
 
Juggernaut Systems Express

Didier Gasser-Morlay

unread,
May 28, 2021, 12:35:30 PM5/28/21
to knock...@googlegroups.com
Two quick and easy tricks

To find out where my code is called from, I manually call the chrome debugger (using the word 'debugger' in my script ) and look at the call stack, if this code is called from somewhere else you will quickly see it; 

To prevent caching issues I also add a parameter in the script tag something like 

<script id="app" src="js/main.js?1622195353"></script>

In my case the html is read through a php script, so before sending I change the value by the current time(); whilst I am developing, on release I fix the time to the time of release, this way I get the best of all worlds : always uptodate whilst developing and benefit of caching on release

Hope this helps, these saved my bacon a few times already

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/knockoutjs/CALsqSrNY7%2BXJxJgpc0zXCTCm6bVRPUAag2QHYgEL5cF1ACHcnw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages