Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
How do you access a mapped sourceParent? #15
Thought I had found all of the caveats, but maybe this is a limitation of mapping ;)
In your seating chart example you have
I tried multiple methods to access it but the common error was
Do I write my own handlers for this?
You are given the observableArray as the targetParent. It is up to you to decide how you will identify it. The mapping plugin will put your items into it with their properties, but it won't add properties directly on the observableArray itself.
So, you could choose to add the id property to your observableArrays yourself or in the "create" callback of the mapping plugin.
Alternatively, you could do some comparison yourself like
Would be happy to help you further with this one.
I think you qualify as Knockout's best evangelist ;)
I tried to do some research before blindly asking for help, but this was as far as I got from this SO question: http://stackoverflow.com/questions/8401799/knockoutjs-adding-observable-properties-and-functions-to-objects-in-a-mapping-g
My usual attempts to then access
If you feel this needs to move to StackOverflow out of GitHub Issues I can open up a question.
In this case, the
Otherwise, you could do:
No problem keeping this issue here. We can keep working on it, until we get it solved for you.
Your method was much more brilliant than my hack.
I created a temporary solution but I was not impressed with its performance: http://jsfiddle.net/DeLongey/ZnhtB/ essentially I parsed the DOM to grab the ID, but that defeats the whole purpose LOL
So to settle this issue and help my understanding (and future readers), in order to access a property I want in the observableArray from a parent, I need to set the child's properties by chaining them when creating the parent (like as in your response).
I was unaware that it would work (I was afraid it would interfere with the child). I can confirm it indeed works :) and in fact this simplifies my coding even further.
Thank you very much! Learned a lot!