Mixin: SC.ContentValueSupport

This mixin allows a view to get its value from a content object based on the value of its contentValueKey.

myView = SC.View.create({
  content: {prop: "abc123"},

  contentValueKey: 'prop'
});

// myView.get('value') will be "abc123"

This is useful if you have a nested record structure and want to have it be reflected in a nested view structure. If your data structures only have primitive values, consider using SC.Control instead.

Defined in: content_value_support.js

Field Summary

Class Methods

Field Detail

SC.ContentValueSupport.content SC.Object

The content object represented by this control.

Often you need to use a control to display some single aspect of an object, especially if you are using the control as an item view in a collection view.

In those cases, you can set the content and contentValueKey for the control. This will cause the control to observe the content object for changes to the value property and then set the value of that property on the "value" property of this object.

Note that unless you are using this control as part of a form or collection view, then it would be better to instead bind the value of the control directly to a controller property.

Default value:
null
SC.ContentValueSupport.contentKeys Hash

Keys that should be observed on the content object and mapped to values on this object. Should be a hash of local keys that point to keys on the content to map to local values. For example, the default is {'contentValueKey': 'value'}. This means that the value of this.contentValueKey will be observed as a key on the content object and its value will be mapped to this.value.

Default value:
null
SC.ContentValueSupport.contentValueKey String

The property on the content object that would want to represent the value of this control. This property should only be set before the content object is first set. If you have a displayDelegate, then you can also use the contentValueKey of the displayDelegate.

Default value:
null
SC.ContentValueSupport.hasContentValueSupport Boolean
Walk like a duck.
Default value:
YES
SC.ContentValueSupport.value Object

The value represented by this control.

Most controls represent a value of some type, such as a number, string or image URL. This property should hold that value. It is bindable and observable. Changing this value will immediately change the appearance of the control. Likewise, editing the control will immediately change this value.

If instead of setting a single value on a control, you would like to set a content object and have the control display a single property of that control, then you should use the content property instead.

Default value:
null

Class Method Detail

contentPropertyDidChange(target, key)

Invoked whenever any property on the content object changes.

The default implementation will update the value property of the view if the contentValueKey property has changed. You can override this method to implement whatever additional changes you would like.

The key will typically contain the name of the property that changed or '*' if the content object itself has changed. You should generally do a total reset if '*' is changed.

Parameters:
target Object
the content object
key String
the property that changes
Returns:
void
updateContentWithValueObserver(target, key)

Relays changes to the value back to the content object if you are using a content object.

This observer is triggered whenever the value changes. It will only do something if it finds you are using the content property and contentValueKey and the new value does not match the old value of the content object.

If you are using contentValueKey in some other way than typically implemented by this mixin, then you may want to override this method as well.

Parameters:
target
key
Returns:
void
updatePropertyFromContent(prop, key, contentKey, content)

Helper method you can use from your own implementation of contentPropertyDidChange(). This method will look up the content key to extract a property and then update the property if needed. If you do not pass the content key or the content object, they will be computed for you. It is more efficient, however, for you to compute these values yourself if you expect this method to be called frequently.

Parameters:
prop String
local property to update
key String
the contentproperty that changed
contentKey String
the local property that contains the key
content Object
Returns:
SC.Control
receiver
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)