0

I was wondering in the following example how I can access the relevant AttributeType property of $parent.contactFields?

as $data looks up fieldCouplings not $parent.contactFields

<ul data-bind="foreach: fieldsCouplings">
   <li>
      <h5 data-bind="text: DisplayName"></h5>                            
      <label>Contact field: <select data-bind="options: $parent.contactFields, optionsText: $data.AttributeType"></select></label>
   </li>
</ul>

I don't seem to be able to find any suitable Binding context in the docs too.

I want to see optionsText to be 0, 1 and 2

Here is an example fiddle: http://jsfiddle.net/makeitmorehuman/86PqH/3/

makeitmorehuman
  • 11,287
  • 3
  • 52
  • 76

1 Answers1

0

In the optionsText you need to pass in property name as a string, in your case 'AttributeType':

<select data-bind="options: $parent.contactFields, optionsText: 'AttributeType'">

Demo JSFiddle.

This is described in documentation of the options binding: Drop-down list representing arbitrary JavaScript objects, not just strings

And later in the parameters section:

optionsText

See Example 3 above to see how you can bind options to an array of arbitrary JavaScript object - not just strings. In this case, you need to choose which of the objects’ properties should be displayed as the text in the drop-down list or multi-select list. Example 3 shows how you can specify that property name by passing an additional parameter called optionsText.

nemesv
  • 138,284
  • 16
  • 416
  • 359