Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. var ViewModel = function () {
  2. self.programs = ko.observableArray([
  3. {programId: 1, programDescription: 'One'},
  4. {programId: 2, programDescription: 'Two'},
  5. {programId: 3, programDescription: 'Three'}
  6. ]);
  7. self.program = ko.observable();
  8.  
  9. self.saveProgram = function () {
  10.  
  11. for (i = 0; i < self.programs().length - 1 ; i++) {
  12. if (self.programs()[i].programId == self.program().programId) {
  13. self.programs()[i].programDescription =
  14. self.program().programDescription;
  15. alert(self.programs()[i].programDescription);
  16. }
  17. }
  18.  
  19. };
  20.  
  21. };
  22.  
  23. ko.applyBindings(new ViewModel());
  24.  
  25. <div>
  26. <select data-bind="options: programs,
  27. optionsText: 'programDescription',
  28. value: program"></select>
  29. </div>
  30. <div>
  31. Update Program Description: <input type="text" data-bind="value: program().programDescription" />
  32. <button type="button" data-bind="click: saveProgram">Update</button>
  33. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement