Guest User

Untitled

a guest
Jul 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <select data-bind="selectedOptions: selectedLength">
  2. // razor code omitted
  3. foreach(var preValue in lengthPreValues)
  4. {
  5. if(lengthPreValues.Contains(preValue.value))
  6. {
  7. <option selected="selected" value='@preValue'>@preValue</ option>
  8. }
  9. else
  10. {
  11. <option value='@preValue'>@preValue</option>
  12. }
  13. }
  14.  
  15. var editOfferViewModel = {
  16. // Properties omitted
  17. selectedLength: ko.observable("")
  18. };
  19.  
  20. ko.applyBindings(editOfferViewModel);
  21.  
  22. var viewModel = {
  23. choices: ko.observableArray(@Html.Raw(Json.Encode(Options))),
  24. selectedChoices: ko.observableArray(@Html.Raw(Json.Encode(SelectedOptions)))
  25. };
  26.  
  27. data-bind="options: choices, selectedOptions: selectedChoices"
  28.  
  29. dataList = [ {name:'length1',id:1},{name:'length2',id:2},{name:'length3',id:3},{name:'length4',id:4},{name:'length5',id:5} ]
  30.  
  31. <select name="xxx" id="xxxid" data-bind="options: dataList, value: selectedLength , optionsText: 'name', optionsValue: 'id', optionsCaption: 'Please Select...'"></select>
  32.  
  33.  
  34. <select name="xxx2" id="xxxid2" data-bind="options: dataList, selectedOptions: multiSelectedLength , optionsText: 'name', optionsValue: 'id', optionsCaption: 'Please Select...'" size="5" multiple="true"></select>
  35.  
  36. var editOfferViewModel = {
  37. selectedLength: ko.observable(),
  38. multiSelectedLength: ko.observableArray()
  39. };
  40.  
  41. ko.applyBindings(editOfferViewModel);
  42.  
  43. $(document).ready(function() {
  44. // Set initial value
  45. editOfferViewModel.selectedLength(2);
  46. // Set inital multi value
  47. editOfferViewModel.multiSelectedLength(['2','3']);
  48. });
Add Comment
Please, Sign In to add comment