本文整理匯總了PHP中TWebControl::onDataBinding方法的典型用法代碼示例。如果您正苦於以下問題:PHP TWebControl::onDataBinding方法的具體用法?PHP TWebControl::onDataBinding怎麽用?PHP TWebControl::onDataBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TWebControl
的用法示例。
在下文中一共展示了TWebControl::onDataBinding方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onDataBinding
/**
* This method is invoked when <b>OnDataBinding</b> event is raised.
*
* Opens up the data source and creates all the TListItem controls
* needed to render the data source.
*
* @param TEventParameter event parameter
*/
protected function onDataBinding($param)
{
parent::onDataBinding($param);
if (is_null($this->dataSource)) {
return;
}
// Reset all values.
$this->items->clear();
$textField = $this->getDataTextField();
$valueField = $this->getDataValueField();
foreach ($this->dataSource as $key => $val) {
if ($val instanceof IListItemSource) {
$text = $val->getItemText();
$value = $val->getItemValue();
} else {
if (strlen($textField)) {
if (isset($val[$textField])) {
$text = $val[$textField];
} else {
throw new Exception('Invalid DataTextField property value');
}
} else {
$text = $val;
}
if (strlen($valueField)) {
if (isset($val[$valueField])) {
$value = $val[$valueField];
} else {
throw new Exception('Invalid DataValueField property value');
}
} else {
$value = $key;
}
}
$item = new TListItem();
$item->setText($text);
$item->setValue("{$value}");
$item->setSelected($this->SelectedValue == $value);
$this->items->add($item);
}
$this->dataSource = null;
}