0

我从 10 月开始,我也在尝试创建一个插件,所以可能是菜鸟问题,但在一段时间内通过网络搜索找不到工作示例,并且文档作为每个单元都很好,但缺少“连接点”恕我直言...我想出了如何使用 SimpleTree 显示与 id 关联的相关名称(可能不是正确的方式)。

https://www.screencast.com/t/WDYkfPdMQ https://www.screencast.com/t/4NDc3HHDs

frmArea.yaml

fields:
id:
    label: Número
    oc.commentPosition: ''
    span: auto
    disabled: 1
    type: number
area_id:
    label: 'Parente de'
    oc.commentPosition: ''
    emptyOption: 'Sem valor'
    span: auto
    type: dropdown
    nameFrom: area
area:
    label: Área
    span: full
    oc.commentPosition: ''
    type: text

面积.php

<?php namespace JML\Gkb\Models;

use Model;

   /**
 * Model
 */
class Area extends Model


{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SimpleTree;

/*
 * Disable timestamps by default.
 * Remove this line if timestamps are defined in the database table.
 */
public $timestamps = false;


/*
 * Validation
 */
public $rules = [
];

/**
 * @var string The database table used by the model.
 */
public $table = 'jml_gkb_areas';

//Relações

public $hasMany = [
    'area_id' => 'JML\Gkb\Models\Area'
];

/*
public $belongsTo = [
    'area_id' => 'JML\Gkb\Models\Area'
]; */

public function getAreaIdOptions(){
    return Area::all()->listsNested('area', 'id');
}


}

如果我创建记录而不选择与父级的任何关系,它们就会被创建(例如图像上的那些)。如果我尝试创建选择父母,它将永远保存...如果我尝试更新 une 记录而不选择父母,那么保存时也会发生同样的情况。

在一段时间内或至少在我清除缓存时,如果没有父级在一段时间后返回锁定超时,我将无法创建记录......好吧,再等一段时间,我在 300 秒后超时......增加的 id 增加了这意味着什么正在调整数据库...我怀疑查询正在发送一个需要数字的字符串,但不知道如何实现...

有人可以在哪里找到一些相关的例子或片段或如何找到一些帮助???并且可以对列表小部件实现相同的结果???

TIA

杰伦

4

1 回答 1

0

好吧,解决了...只需挖掘 SimpleTree 特征代码即可了解它的工作原理...惊人的简单...

<?php namespace JML\Gkb\Models;

使用模型;

/**
 * Model
 */
class Area extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SimpleTree;

/*
 * Disable timestamps by default.
 * Remove this line if timestamps are defined in the database table.
 */
public $timestamps = false;
const PARENT_ID = 'area_id';


/*
 * Validation
 */
public $rules = [
];

/**
 * @var string The database table used by the model.
 */
public $table = 'jml_gkb_areas';

//Relações

public function getAreaIdOptions(){

    return Area::all()->listsNested('area', 'id');

}


}

只需要删除关系并添加

const PARENT_ID = 'area_id';

因为那是与 id 有关系的列。

如果有人知道如何通过 Builder 列表小部件上的描述更改“area_id”的答案,请随时发表评论。

TIA

于 2017-03-04T16:02:56.213 回答