带有 dhtmlx 调度程序的 yii2 并选择从服务器填充 [英] yii2 with dhtmlx scheduler and select populated from the server

查看:17
本文介绍了带有 dhtmlx 调度程序的 yii2 并选择从服务器填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用来自服务器的数据填充项目选择下拉列表.我正在使用 yii2.

I am trying to populate the project select dropdown with data from the server. I am using yii2.

我的控制器数据操作:

public function actionData()
{
    $list = new OptionsConnector(null, "PHPYii");
    $list->render_table("project", "id", "id(value),name(label)");
    $connector = new JSONSchedulerConnector(null, "PHPYii");
    $connector->set_options("project", $list);
    $connector->configure(
        new Booking(), "id", "start, end, activity, user, subsubproject, status, comment"
    );
    $connector->render();
}

我收到一条错误消息:

异常错误",消息为调用成员函数 find() on字符串'

Exception 'Error' with message 'Call to a member function find() on string'

我认为这一行是原因:$connector->set_options("project", $list);

我应该改变什么?

更新:所以我现在在这里:

UPDATE: So I am here now:

public function actionData() {
    $list = new JSONOptionsConnector(null, "PHPYii");
    $list->enable_log("text1.log");
    $list->configure(
        new Subsubproject(),
            "-","id, name"
    );
    $list->render();
    $connector = new JSONSchedulerConnector(null, "PHPYii");
    $connector->enable_log("text2.log");
    $connector->set_options("subsubprojects", $list);
    $connector->configure(
        new Booking(),
            "id", "start, end, activity, user, subsubproject, status,comment"
    );
    $connector->render();
}

我明白了:

0: Object { key: undefined, id: 1, name: "Thing1", … }
​1: Object { key: undefined, id: 2, name: "Thing2", … }
​2: Object { key: undefined, id: 3, name: "Thing3", … }

我没有钥匙……我怎样才能得到一些?:)

I don't have keys... How can I get some? :)

推荐答案

1) 不需要直接调用 JSONOptionsConnector 的 render 方法.如果我没记错的话,调用它会结束请求的处理,因此 SchedulerConnector 不起作用尝试注释掉 $list->render(); 行.

1) You don't need to call the render method of JSONOptionsConnector directly. Calling it ends processing of the request if I'm not mistaken, so the SchedulerConnector takes no effect Try commenting out $list->render(); line.

2) 响应格式似乎有点不对.这可能是 dhtmlx 连接器的 PHPYii 包装器的错误,我不确定

2) The response format seems a bit off. This may be a bug of PHPYii wrapper of dhtmlx connector, I'm not sure

根据源代码 客户端需要来自选项的 valuelabel 属性,而处理程序返回 idname.

According to source codes the client-side needs value and label properties from options, and while handler returns id and name.

您可以尝试以下操作:

public function actionData() {
    $list = new JSONOptionsConnector(null, "PHPYii");
    $list->enable_log("text1.log");
    $list->configure(
        new Subsubproject(),
            "id","id(value), name(label)"
            // or 
            // "id(value)","id(value), name(label)"
    );

    $connector->enable_log("text2.log");
    $connector->set_options("subsubprojects", $list);
    $connector->configure(
        new Booking(),
            "id", "start, end, activity, user, subsubproject, status,comment"
    );
    $connector->render();
}

这应该会生成一个包含预订和子项目列表的 json 响应.但是,我无法测试此代码,因此可能仍有问题.你可以试一下,看看结果 JSON 是否正确.

This should produce a json response containing a list of booking and subprojects. However, I can't test this code so something may still be wrong. You can try it and see whether the result JSON looks right.

如果它不能让你更接近,老实说我会手动生成 json 而不是使用带有 PHPYii 包装器的连接器.这样您就可以直接控制从控制器返回的内容,并且不会再有另一个黑匣子.

If it doesn't get you any closer, I honestly would produce json manually rather than using a connector with PHPYii wrapper. That way you'll have direct control over what is returned from your controller and won't have another black box there.

您需要从您的操作中返回以下结构的 json:https://docs.dhtmlx.com/scheduler/data_formats.html#jsonwithcollections

You'll need to return a json of the following structure from your action: https://docs.dhtmlx.com/scheduler/data_formats.html#jsonwithcollections

所以你会在你的行动中得到这样的东西:

so you'll have something like this in your action:

return $this->asJson([
  "data"=> $preparedEventsArray
  "collections" => [
      "subprojects"=> $preparedSubprojects
   ]
]);

其中 $preparedEventsArray 是文档中显示的事件对象数组,而 $subprojects - 您的值/标签对象

where $preparedEventsArray is an array of event objects as shown in docs, and $subprojects - your value/label objects

请注意,data 集合中的属性名称 - "id","start_date","end_date","text" - 是强制性的,您必须将数据模型映射到此结构体,例如

Note that names of properties in the data collection - "id","start_date","end_date","text" - are mandatory, you'll have to map your data model to this structure, e.g.

start -> start_date
end -> end_date
activity -> text

所有其他属性的名称可以保持不变.

all other properties can have their names unchanged.

不幸的是,官方文档没有 Yii2 的示例代码.有服务器格式的通用文档https://docs.dhtmlx.com/scheduler/server_integration.html以及 PHP Slim 框架和 Laravel,这不是您所需要的,而是当前文档中最接近的.

The official docs don't have a sample code for Yii2, unfortunately. There are common docs for server formats https://docs.dhtmlx.com/scheduler/server_integration.html And tutorials for PHP Slim framework and Laravel, which is not exactly what you need, but the closest thing the current documentation has.

这篇关于带有 dhtmlx 调度程序的 yii2 并选择从服务器填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆