computeData

  • function
can.view.Scope.computeData  

scope.computeData(key, options)

Parameters

  1. key {key}

    A dot seperated path. Use "." if you have a property name that includes a dot.

  2. options {readOptions}Optional

    Options that configure how the key gets read.

Returns

{Object}

An object with the following values:

  • compute {can.compute(getterSetter, context)}

    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.

  • scope {can.view.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 key value in a template. Configure how it reads values in the scope and what values it returns with the 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"