milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. JavaScript
  4. Knockout

Options binding

Details
Written by: Stanko Milosev
Category: Knockout
Published: 01 October 2013
Last Updated: 01 October 2013
Hits: 1278

Just a short note to myself, what we need for options binding, so that it can work properly. 

<select autowidth="true" data-bind="
	options: $root.carTypes
	,optionsValue: 'carValue'
	,value: myTest
"></select>

Where myTest is like:

function CarsView(initialValues) {
	var self = this;	
	self.myTest = ko.observable(initialValues);
}

If we need model to pass, then model should look like:

carsModel = 
	[
		{ 
			carTypes: ko.observable('Ferrari'),
			myTest: ko.observable('Ferrari')
		}
	];

Options binding

Details
Written by: Stanko Milosev
Category: Knockout
Published: 01 October 2013
Last Updated: 01 October 2013
Hits: 6391

Just a short note to myself, what we need for options binding, so that it can work properly. 

<select autowidth="true" data-bind="
	options: $root.carTypes
	,optionsValue: 'carValue'
	,value: myTest
"></select>

Where myTest is like:

function CarsView(initialValues) {
	var self = this;	
	self.myTest = ko.observable(initialValues);
}

If we need model to pass, then model should look like:

carsModel = 
	[
		{ 
			carTypes: ko.observable('Ferrari'),
			myTest: ko.observable('Ferrari')
		}
	];

Not finished example you can see here.

Attributes

Details
Written by: Stanko Milosev
Category: Knockout
Published: 01 October 2013
Last Updated: 30 November -0001
Hits: 4270

If you want to bind attributes, then declare them under the quotes, something like:

 

attr: {id: 'availableSensorsId' + $index()}

Where $index is binding context

applyBindings

Details
Written by: Stanko Milosev
Category: Knockout
Published: 01 October 2013
Last Updated: 01 October 2013
Hits: 4352

When we want to apply bindings on the particular element using jquery, we should use following code:

ko.applyBindings(new CarsViewModel(), $('#form0')[0]);

Zero ([0]) is important, otherwise it will not work.

  1. Closing tags
  2. self = this
  3. Autocomplete
  4. Change the value of drop down list

Page 4 of 6

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6