can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
42 lines (29 loc) • 1.48 kB
Markdown
Scope.computeData computeData
can.view.Scope.prototype
{can.mustache.key} key A dot seperated path. Use `"\."` if you have a
property name that includes a dot.
{can.view.Scope.readOptions} [options] Options that configure how the `key` gets read.
{{}} An object with the following values:
{can.compute} compute A compute that returns the
value of `key` looked up in the scope's context or parent context. This compute can
also be written to, which will set the observable attribute or compute value at the
location represented by the key.
{can.view.Scope} scope The scope the key was found within. The key might have
been found in a parent scope.
{*} initialData The initial value at the key's location.
## Use
`scope.computeData(key, options)` is used heavily by [can.mustache] to get the value of
a [can.mustache.key key] value in a template. Configure how it reads values in the
scope and what values it returns with the [can.view.Scope.readOptions options] argument.
var context = new Map({
name: {first: "Curtis"}
})
var scope = new can.view.Scope(context)
var computeData = scope.computeData("name.first");
computeData.scope === scope //-> true
computeData.initialValue //-> "Curtis"
computeData.compute() //-> "Curtis"
The `compute` value is writable. For example:
computeData.compute("Andy")
context.attr("name.first") //-> "Andy"
can.view.