OctoberCMS:Ajax 处理程序
OctoberCMS: Ajax Handler
我已经使用 Builder 创建了一个插件。
有 2 个模型:
- 提供商
- 位置
我正在尝试在前端创建 3 个独立的过滤器,以便用户可以按名称及其位置过滤提供商列表。
这是我的提供商模型
<?php namespace JacobFeeley\Matrix\Models;
use Model;
/**
* Model
*/
class Provider extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'jacobfeeley_matrix_providers';
/**
* @var array Validation rules
*/
public $rules = [
];
public $jsonable = [
'contacts',
'courses'
];
public $belongsTo = [
'location' => 'JacobFeeley\Matrix\Models\Location'
];
public function scopeApplyTitle($query, $title)
{
return $query->where('title', $title);
}
public function scopeApplyLocation($query, $location)
{
return $query->where('location', $location);
}
}
我的位置模型
<?php namespace JacobFeeley\Matrix\Models;
use Model;
/**
* Model
*/
class Location extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'jacobfeeley_matrix_locations';
/**
* @var array Validation rules
*/
public $rules = [
];
public $hasMany = [
'providers' => 'JacobFeeley\Matrix\Models\Providers',
'courses' => 'JacobFeeley\Matrix\Models\Courses'
];
public function scopeApplyTitle($query, $title)
{
return $query->where('title', $title);
}
public function scopeApplyProvider($query, $provider)
{
return $query->where('provider', $provider);
}
}
}
我现在可以以此为例来获取伦敦的所有提供商:
Provider::applyLocation('London')->get();
我不知道如何填充 2 个前端下拉菜单
- 所有供应商第一
- 第二个包含所有位置
这是我的组件
<form>
<div class="form-group row">
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected disabled>Select Provider</option>
</select>
</div>
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected disabled>Select Location</option>
</select>
</div>
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected>Select Course</option>
</select>
</div>
</div>
</form>
如果有人能帮我解决代码,我将不胜感激
您的表单应如下所示:
<form>
<div class="form-group row">
<div id="providers" class="form-group col-md-4">
{% partial "@providers" %}
</div>
<div id="locations" class="form-group col-md-4">
{% partial "@locations" %}
</div>
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected>Select Course</option>
</select>
</div>
</div>
</form>
providers.htm
部分:
<select data-request="onSelectProvider" class="form-control s2">
<option selected disabled>Select Provider</option>
{% for provider in providers %}
<option value="{{ provider.id }}">{{ provider.name }}</option>
{% endfor %}
</select>
和locations.htm
:
<select data-request="onSelectLocation" class="form-control s2">
<option selected disabled>Select Location</option>
{% for location in locations %}
<option value="{{ locations.id }}">{{ locations.name }}</option>
{% endfor %}
</select>
当然,您需要调整引用模型中的字段名称,因为我没有您的实施细节。
我已经使用 Builder 创建了一个插件。
有 2 个模型:
- 提供商
- 位置
我正在尝试在前端创建 3 个独立的过滤器,以便用户可以按名称及其位置过滤提供商列表。
这是我的提供商模型
<?php namespace JacobFeeley\Matrix\Models;
use Model;
/**
* Model
*/
class Provider extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'jacobfeeley_matrix_providers';
/**
* @var array Validation rules
*/
public $rules = [
];
public $jsonable = [
'contacts',
'courses'
];
public $belongsTo = [
'location' => 'JacobFeeley\Matrix\Models\Location'
];
public function scopeApplyTitle($query, $title)
{
return $query->where('title', $title);
}
public function scopeApplyLocation($query, $location)
{
return $query->where('location', $location);
}
}
我的位置模型
<?php namespace JacobFeeley\Matrix\Models;
use Model;
/**
* Model
*/
class Location extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'jacobfeeley_matrix_locations';
/**
* @var array Validation rules
*/
public $rules = [
];
public $hasMany = [
'providers' => 'JacobFeeley\Matrix\Models\Providers',
'courses' => 'JacobFeeley\Matrix\Models\Courses'
];
public function scopeApplyTitle($query, $title)
{
return $query->where('title', $title);
}
public function scopeApplyProvider($query, $provider)
{
return $query->where('provider', $provider);
}
}
}
我现在可以以此为例来获取伦敦的所有提供商:
Provider::applyLocation('London')->get();
我不知道如何填充 2 个前端下拉菜单
- 所有供应商第一
- 第二个包含所有位置
这是我的组件
<form>
<div class="form-group row">
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected disabled>Select Provider</option>
</select>
</div>
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected disabled>Select Location</option>
</select>
</div>
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected>Select Course</option>
</select>
</div>
</div>
</form>
如果有人能帮我解决代码,我将不胜感激
您的表单应如下所示:
<form>
<div class="form-group row">
<div id="providers" class="form-group col-md-4">
{% partial "@providers" %}
</div>
<div id="locations" class="form-group col-md-4">
{% partial "@locations" %}
</div>
<div class="form-group col-md-4">
<select data-request="" class="form-control s2">
<option selected>Select Course</option>
</select>
</div>
</div>
</form>
providers.htm
部分:
<select data-request="onSelectProvider" class="form-control s2">
<option selected disabled>Select Provider</option>
{% for provider in providers %}
<option value="{{ provider.id }}">{{ provider.name }}</option>
{% endfor %}
</select>
和locations.htm
:
<select data-request="onSelectLocation" class="form-control s2">
<option selected disabled>Select Location</option>
{% for location in locations %}
<option value="{{ locations.id }}">{{ locations.name }}</option>
{% endfor %}
</select>
当然,您需要调整引用模型中的字段名称,因为我没有您的实施细节。