-1

I am new to both Knockout and jQuery-Templates. I am trying to do something similar to this in that I need to be able to add entities related to a parent entity. In the example link, he is using a library called knockout-sortable in order to get <li> sorting functionality. I am not in need of that functionality and am having a hard time figuring out the correct code changes to make it work. Currently I am receiving no error, yet also no functionality. I am completely lost.

TLDR: http://jsfiddle.net/jpm0004/LkqTU/15412/

Update: I would actually prefer to do this using Knockout templates instead after further research. I've found this page which looks extremely promising.

8
  • 1
    There's also knockoutjs.com/documentation/template-binding.html, which use the type="text/html" for templates
    – PMC
    Mar 16, 2014 at 19:38
  • Yep, I was looking at Note 2 on that page. It looks like I just needed to ask a SO question to make my brain work. There are many issues with the above fiddle. Mar 16, 2014 at 19:42
  • What is the end goal here? Just to be able to add movies to a parent data element? How do I know when I've fixed the problem?
    – arb
    Mar 16, 2014 at 19:47
  • That's it. I just need to be able to add/remove movies from the viewModel. I know it sounds simple, but I'm in the process of peeling my brain off of 100% server-side methodologies. When I initially asked the question, I was under the impression this was much more difficult than it actually is. Mar 16, 2014 at 19:52
  • 1
    I've changed you're jsfiddle slightly to show how I would start to tackle it. Haven't added a template to it. The first reason it wasn't working was it was missing applybindings jsfiddle.net/pmccowat/S8G9t
    – PMC
    Mar 16, 2014 at 20:01

1 Answer 1

1

I've changed your jsfiddle here slightly to get it working and show how I would lay things out.

The first reason it wasn't working was it was missing ko.applybindings

5
  • 1
    I made a slight adjustment to the way you were attaching the remove handler as it wasn't really the "right" way to do it with Knockout. Small change here jsfiddle.net/S8G9t/3 if you want to update your answer.
    – arb
    Mar 16, 2014 at 20:40
  • Thanks Zero21xxx, I copy and pasted the first tutorials code and never read that far down!
    – PMC
    Mar 16, 2014 at 20:44
  • After messing with your example a little more, I noticed that if you add a new movie, and change the Title and Rating, the value(s) don't update under the "You have X favorite movies." span. How could we fix that? Mar 16, 2014 at 21:15
  • It depends on how you want it to update. You could have an update button and keep things as they are, or you could make these properties observables either manually or using the mapping plugin and they would auto-update. This was the reason I added the text list but stopped from going too far in this example.
    – PMC
    Mar 16, 2014 at 21:19
  • jsfiddle.net/pmccowat/t42KF/1 this is with manual mappings to an object with observables.
    – PMC
    Mar 16, 2014 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.