本文整理匯總了PHP中Renderer::renderJS方法的典型用法代碼示例。如果您正苦於以下問題:PHP Renderer::renderJS方法的具體用法?PHP Renderer::renderJS怎麽用?PHP Renderer::renderJS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Renderer
的用法示例。
在下文中一共展示了Renderer::renderJS方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateCRUDform
/**
* @param \Illuminate\Database\Eloquent\Model $model
* @param $id
* @param $showFields
* @param array $fieldsNames
* @param array $selectsOptions
* @param array $extraParams
* @return string
*/
public static function generateCRUDform($model, $id, $showFields, $fieldsNames = array(), $selectsOptions = array(), $extraParams = array(), $defaultValues = array())
{
$renderer = new Renderer();
$modelObject = $model::find($id);
$btnName = "Modificar ficha";
if (!$modelObject) {
$modelObject = new $model();
$btnName = "Añadir";
}
$extraParams['class'][] = "form-horizontal";
$extraParams['class'][] = "autoGeneratedCRUDForm";
$extraParams['role'] = "form";
$extraParams['method'] = "post";
Renderer::addJS("\n <script>\n \$(function(){\n \$('.autoGeneratedCRUDForm').on('submit', function(e){\n var form = \$(this);\n \$('.autoGeneratedCRUDForm input[type=checkbox]').each(function()\n {\n if(\$(this).prop('checked')) {\n form.append('<input type=\"hidden\" name=\"'+\$(this).attr('name')+'\" value=\"1\">');\n }\n else form.append('<input type=\"hidden\" name=\"'+\$(this).attr('name')+'\" value=\"0\">');\n \$(this).remove();\n });\n return true;\n });\n });\n </script>\n ");
$htmlParams = $renderer->generateHtmlParams($extraParams);
$result = "<form {$htmlParams}>";
$result .= $renderer->generate2columnsFormContent($showFields, $modelObject, $fieldsNames, $selectsOptions, $defaultValues);
$result .= "<div class='row form-group text-center'>\n\t\t\t\t\t\t<button class='btn btn-success'>{$btnName}</button>\n\n\t\t\t\t\t</div>";
$result .= "</form>";
$result .= $renderer->renderJS();
return $result;
}