2

In handlebars.net, I know we can access array members like

{{SomeArray.0}}

Is it possible to access collection items through indexers like

{{SomeCollectionInstance['key']}}

or

{{SomeCollectionInstance.key}}

If not possible, can anyone propose a way to implement it, at least for string and numeric indexers?

Onur Okyay
  • 190
  • 1
  • 10

1 Answers1

2

For dictionaries and objects, the .keyName or .propertyName notations are supported.

You can also use .[key name] or .[property name] (square brackets) - this is useful for situations where the property name has a weird character in it, like a space.

Rex M
  • 142,167
  • 33
  • 283
  • 313
  • Thanks for the info but the actual question was accessing through indexers like `public object this[string fieldName] { get { return fieldValue; } }` Any comments on this? – Onur Okyay Jun 27 '18 at 05:42
  • It is not supported for an arbitrary class. If the class implements IDictionary it would work. – Rex M Jun 28 '18 at 12:18
  • Using IDictionary looks like a very good idea. Thanks for pointing this out. – Onur Okyay Jun 29 '18 at 12:22