您好我正在使用Laravel和Jquery创建一个项目,该项目可以从许多列表中分配给任务的许多状态。需要将状态写入assigned_statuses
表,其中project_id
和status_id
形成相关关系。
要分配这些,我有两个连接的可排序列表,它们有两个隐藏的输入,我正在使用sortable,因为项目中的任务将按照回发时分配的特定顺序移动。无论如何,我渲染的刀片文件输出名为statuses
的隐藏表单,并将它们全部发回。但是我需要知道哪些是指定的。到目前为止,这是我的代码:
<div class="statuses">
<div class="statussortableWrapper">
<ul id="available-statuses" name="available-statuses" class="connected-sortable">
@foreach($statuses as $status)
<li class="ui-state-default" id="{{$status->id}}" name="{{$status->id}}">
{{Form::hidden('available-statuses[]',$status->id,array('class' => 'sortable-hidden-input'))}}
<span class="label label-primary">{{$status->name}}</span>
</li>
@endforeach
</ul>
</div>
<div class="statussortableWrapper">
<ul id="assigned-stauses" name="assigned-stauses" class="connected-sortable">
</ul>
</div>
</div>
$(function() {
$( "#available-statuses, #assigned-stauses" ).sortable({
connectWith: ".connected-sortable",
stop: function(event, ui) {
var present = $(ui.item).find('.sortable-hidden-input').attr("name", "assigned-statuses[]");
console.log(present);
}
}).disableSelection();
});
在具有.sortable-hidden-input
类的输入上更改了name属性,但是当回发它时,它没有数组中的键名,数组如下:
array(7) {
["project_name"] ""
["start_date"] "01/01/2015"
["end_date"] "13/03/2015"
["available-statuses"] array(2) {
[0] "17"
[1] "20"
}
array(3) {
[0] "19"
[1] "16"
[2] "18"
}
}
正如您所看到的,可用状态位于其自己的数组中,但其他已分配的状态ID不是。我不确定为什么代码在输入上成功分配了新的name属性。我有什么想法,以及如何在后端成功捕获它?
状态转储:
array(5) {
[0] array(8) {
["id"] "16"
["name"] "Backlog"
["order"] "0"
["created_at"] "2015-07-19 17:41:25"
["updated_at"] "2015-07-19 20:29:20"
}
[1] array(8) {
["id"] "17"
["name"] "Open"
["order"] "4"
["created_at"] "2015-07-19 17:41:25"
["updated_at"] "2015-07-19 20:29:11"
}
[2] array(8) {
["id"] "18"
["name"] "In Progress"
["order"] "1"
["created_at"] "2015-07-19 17:41:25"
["updated_at"] "2015-07-19 20:29:11"
}
[3] array(8) {
["id"] "19"
["name"] "Review"
["order"] "2"
["created_at"] "2015-07-19 17:41:25"
["updated_at"] "2015-07-19 20:29:21"
}
[4] array(8) {
["id"] "20"
["name"] "Done"
["order"] "3"
["created_at"] "2015-07-19 17:41:25"
["updated_at"] "2015-07-19 20:30:14"
}
}
完整表格
@extends('layouts.master')
@section('content')
<div class="create-project-layout">
<div class="page-intro">
<h3>Create new Project</h3>
<span>* required fields</span>
</div>
<div class="all-project">
{{ Form::open(array('url' => route('project.add'), 'class'=> 'create-project-form')) }}
<div class="form-group">
{{ Form:: label ('project_name', 'Project name *' )}}
{{ Form:: text ('project_name', '', array('placeholder' => 'Project Two', 'class' =>'form-control', 'id' => 'project-name') )}}
</div>
<div class="form-group">
{{ Form:: label ('start_date', 'Start Date *' )}}
<div class='input-group date'>
{{ Form:: text ('start_date', '', array('placeholder' => '2015/08/31', 'class' =>'form-control', 'data-provide' => 'datepicker', 'data-date-format' => 'yyyy/mm/dd', 'id' => 'start_date') )}}
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="form-group">
<div class="">
{{ Form:: label ('end_date', 'End Date *' )}}
<div class='input-group date'>
{{ Form:: text ('end_date', '', array('placeholder' => '2015/08/31', 'class' =>'form-control', 'data-provide' => 'datepicker', 'data-date-format' => 'yyyy/mm/dd', 'id' => 'end_date') )}}
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="form-group">
{{Form::label('globalstatues', 'These statuses have been assigned globally to all projects.')}}
@foreach($globalstatuses as $status)
<span class="label label-primary">{{$status->name}}</span>
@endforeach
</div>
{{Form::label('overideglobalstatues', 'Would you like to override?')}}
<div class="override-status">
<p>The statuses on the left are available for selection. Drag them to the area on the right in the order you would like the scrum board to run. E.g. Backlog > In Progress > Review > Done > Deloyped.</p>
<div class="statussortableWrapper">
<ul id="available-statuses" name="available-statuses" class="connected-sortable">
@foreach($statuses as $status)
<li class="ui-state-default" id="{{$status->id}}" name="{{$status->id}}">{{Form::hidden('status[]',$status->id,array('class' => 'sortable-hidden-input'))}}<span class="label label-primary">{{$status->name}}</span></li>
@endforeach
</ul>
</div>
<div class="statussortableWrapper">
<ul id="assigned-stauses" name="assigned-stauses" class="connected-sortable">
</ul>
</div>
</div>
<div class="form-group">
{{ Form::submit('Create new project', array('class' => 'btn btn-success', 'id'=> 'create-project')) }}
{{ Form::close() }}
</div>
</div>
</div>
@stop
答案 0 :(得分:1)
您的代码应该可以工作,这看起来像一个格式化的数组:
array(7) {
["project_name"] ""
["start_date"] "01/01/2015"
["end_date"] "13/03/2015"
["available-statuses"] array(2) {
[0] "17"
[1] "20"
}
array(3) {
[0] "19"
[1] "16"
[2] "18"
}
}
右键点击浏览器并查看来源,看看内容是否不同。