Saltar para o conteúdo principal
Versão: Próximo

VP SET DATA CONTEXT

História
ReleaseMudanças
19 R5Adicionado

VP SET DATA CONTEXT ( vpAreaName : Text ; dataObj : Object {; options : Object } {; sheet : Integer} )
VP SET DATA CONTEXT ( vpAreaName : Text ; dataColl : Collection ; {options : Object } {; sheet : Integer} )

ParâmetroTipoDescrição
vpAreaNameObject->Nome de objeto formulário área 4D View Pro
dataObjObject->Objeto dados a carregar no contexto de dados
dataCollCollection->Recolha de dados a carregar no contexto de dados
optionsObject->Opções adicionais
sheetInteger->Índice da folha

Descrição

O comando VP SET DATA CONTEXT define o contexto de dados de uma folha. A data context is an object or a collection bound to a worksheet, and whose contents can be used to automatically fill the sheet cells, either by using an autogenerate option or the VP SET BINDING PATH method. On the other hand, the VP Get data context command can return a context containing user modifications.

Em vpAreaName, passe o nome da área 4D View Pro. Se passar um nome que não existe, é devolvido um erro.

In dataObj or dataColl, pass an object or a collection containing the data to load in the data context. As imagens são convertidas em esquemas URI de dados.

To pass a time value in dataObj or dataColl, encapsulate it in an object with the following properties (see example 4):

PropriedadeTipoDescrição
valueInteger, Real, Boolean, Text, Date, NullValor a inserir no contexto
timeRealValor de hora (em segundos) a introduzir no contexto

In options, you can pass an object that specifies additional options. As propriedades possíveis são:

PropriedadeTipoDescrição
resetObjectTrue to reset the sheet's contents before loading the new context, False (default) otherwise.
autoGenerateColumnsObjectApenas utilizado quando os dados são uma coleção. True (default) to specify that columns must be generated automatically when the data context is bound. In this case, the following rules apply:
  • If dataColl is a collection of objects, attribute names are used as column titles (see example 2).
  • If dataColl contains subcollections of scalar values, each subcollection defines the values in a row (see example 3). The first subcollection determines how many columns are created.

In sheet, pass the index of the sheet that will receive the data context. Se nenhum índice for passado, o contexto será aplicado à folha atual.

If you export your document to an object using VP Export to object, or to a 4DVP document using VP EXPORT DOCUMENT, the includeBindingSource option lets you copy the contents of the current contexts as cell values in the exported object or document. Para obter mais detalhes, consulte a descrição desses métodos.

Exemplo

Passa um objeto e associa os dados de contexto às células da primeira linha:

var $data : Object

$data:=New object

$data.firstName:="Freehafer"
$data.lastName:="Nancy"

VP SET DATA CONTEXT("ViewProArea"; $data)

VP SET BINDING PATH(VP Cell("ViewProArea"; 0; 0); "firstName")
VP SET BINDING PATH(VP Cell("ViewProArea"; 1; 0); "lastName")

Exemplo 2

Passe uma coleção de objetos e gere colunas automaticamente:

var $options : Object
var $data : Collection

$data:=New collection()
$data.push(New object("firstname"; "John"; "lastname"; "Smith"))
$data.push(New object("firstname"; "Mary"; "lastname"; "Poppins"))

$options:=New object("autoGenerateColumns"; True) VP SET DATA CONTEXT("ViewProArea"; $data; $options)

Exemplo 3

The data passed as a parameter is a collection that contains subcollections. Cada subcoleção define o conteúdo de uma linha:

var $data : Collection
var $options : Object

$data:=New collection
$data.push(New collection(1; 2; 3; False; "")) // 5 columns are created
$data.push(New collection) // Second row is empty
$data.push(New collection(4; 5; Null; "hello"; "world")) // Third row has 5 values
$data.push(New collection(6; 7; 8; 9)) // Fourth row has 4 values

$options:=New object("autoGenerateColumns"; True) VP SET DATA CONTEXT("ViewProArea"; $data; $options)

Exemplo 4 - Sintaxe de data e hora

var $data : Collection
var $options : Object

$data:= New collection()

// Dates can be passed as scalar values
$data.push(New collection("Date"; Current date))

// Time values must be passed as object attributes
$data.push(New collection("Time"; New object("time"; 5140)))

// Date + time example
$data.push(New collection("Date + Time"; New object("value"; Current date; "time"; 5140)))

$options:=New object("autoGenerateColumns"; True) VP SET DATA CONTEXT("ViewProArea"; $data; $options)

Eis o resultado após as colunas serem geradas:

Veja também

VP SET BINDING PATH
VP Get binding path
VP Get data context