RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-291233

IlyaDrummer's questions

Martin Hope
IlyaDrummer
Asked: 2022-06-27 11:30:43 +0000 UTC

如何递归构建树?

  • 0

有一个包含数据的数组。

    $tree = [
    0 => [
        ['id' => 1, 'title' => 'Russia', 'type' => 'country', 'parent_id' => 0],
        ['id' => 2, 'title' => 'Usa', 'type' => 'country', 'parent_id' => 0],
    ],
    1 => [
        ['id' => 3, 'title' => 'Khakassia', 'type' => 'region', 'parent_id' => 1],
        ['id' => 4, 'title' => 'Krasnoyarsk krai', 'type' => 'region', 'parent_id' => 1],
        ['id' => 5, 'title' => 'Texas', 'type' => 'region', 'parent_id' => 2],
        ['id' => 6, 'title' => 'California', 'type' => 'region', 'parent_id' => 2],
    ],
    2 => [
        ['id' => 7, 'title' => 'Abakan', 'type' => 'region', 'parent_id' => 3],
        ['id' => 8, 'title' => 'Abaza', 'type' => 'region', 'parent_id' => 3],
        ['id' => 9, 'title' => 'Krasnoyarsk', 'type' => 'region', 'parent_id' => 4],
        ['id' => 10, 'title' => 'Norilsk', 'type' => 'region', 'parent_id' => 4],
        ['id' => 11, 'title' => 'Dallas', 'type' => 'region', 'parent_id' => 5],
        ['id' => 12, 'title' => 'Houston', 'type' => 'region', 'parent_id' => 5],
        ['id' => 13, 'title' => 'Los Angeles', 'type' => 'region', 'parent_id' => 6],
        ['id' => 14, 'title' => 'Sacramento', 'type' => 'region', 'parent_id' => 6],
    ],
];

我不知道如何递归地锐化一棵树。我可以添加元素和嵌套。

Russia
    - Khakassia
        - Abakan
        - Abaza
    - Krasnoyarsk krai
        - Krasnoyarsk
        - Norilsk

Usa
    - Texas
        - Dallas
        - Houston
    - California
        - Los Angeles
        - Sacramento
php
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2022-06-22 17:33:04 +0000 UTC

如何通过查询字符串过滤输出?

  • 0

我有一个用户和状态表以及一个链接表。

就像通过查询字符串一样:api/user?status=free

只会显示具有此状态的用户。

我不知道如何通过链接表显示记录

用户:

身份证名称

1 伊万

2

3尼娜

地位:

身份证标题

1 免费

2 忙

3 不可用

用户状态:

user_id status_id

13

12

十一

控制器

public function index(Request $request)
{
    $status = $request->get('status');
    $users = User::with('status')->get();
    
    return $users;

}
laravel
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2022-04-01 21:53:39 +0000 UTC

在数据库中创建记录时,不分配user_id?

  • 0

创建条目时(用户创建密码,选择类别)。如何实现以便可以在没有 user_id 的情况下创建记录,选中常规框,在数据库中,该记录将变为没有 user_id。

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request) {
    $id = Auth::user()->id;
    $pass = new Pass();
    $pass->title = $request->title;
    $pass->category_id = $request->category_id;
    $pass->user_id = $id;
    $pass->save();
    return redirect()->route('home');
}

我们在其中创建条目(密码)的视图中的片段

<div class="form-group">
<input name="title" type="text" class="form-control"  required value="{{ $pass->title ?? ''}}">
</div>
<div class="form-group">
    <label for="category_id">Категория</label>
    <select name="category_id" id="category_id" class="form-control">
        @foreach ($categorys as $category)
            <option value="{{$category->id}}">{{$category->title}}</option>
        @endforeach
    </select>
</div>
laravel
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2022-03-25 15:35:24 +0000 UTC

如何从两个连接表中输出值?

  • 0

有两个表,用户和帖子。我需要向用户显示属于他的帖子中的帖子。

用户表
ID:1
名称:Alex

id:2
姓名:Ilya

帖子表
id:1
标题:好消息
user_id:1

id: 2
title: 好消息
user_id: 2

id: 3
title: 不错的好消息
user_id: 2

需要这个结果:
亚历克斯
好消息

伊利亚
好消息
不错 好消息

我现在得到的是:
出于某种原因,
Alex对象不是标题,而是
[{"id":1,"title":"Good News.","user_id":1,"}]

Ilya
[{"id":2,"title":"好消息。","user_id":2,"}]
[{"id":3,"title":"不错的好消息。"," user_id":2,"}]

后模型:

public function user()
{
    return $this->belongsTo(User::class);
}

用户模型:

public function posts()
{
    return $this->hasMany(Post::class, 'user_id', 'id');
}

控制器

$users = User::with('posts')->get();
    $posts = Post::with('user')->get();
    return view('index', compact('users', 'posts'));

看法:

@foreach ($users as $user)
<h3>{{ $user->name}}</h3>
    @foreach ($posts as $post)
        <p>{{ $post->title }}</p>
    @endforeach
@endforeach
laravel
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-09-01 10:42:13 +0000 UTC

如何将数据从 console.log 传输到 json 文件?

  • 0

有一个将数据输出到console.log的脚本,如何将console.log中的数据放到一个单独的json文件中?

var store = require('app-store-scraper');

store.search({
 term: 'ninja',
 num: 2,
 page: 3,
 country : 'us',
 lang: 'lang'
 })
  .then(console.log)
  .catch(console.log);
javascript
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-08-26 21:02:37 +0000 UTC

错误,类不存在,如何解决?

  • 1

创建表单时,我为字段分配了一个类。发生错误,类:TextareaType、ChoiceType、DateTimeType 不存在。

在此处输入图像描述

<?php

    namespace App\Form;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use App\Entity\Notes;
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolver;

    class NotesType extends AbstractType
    {
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
     $builder
        ->add('title', TextType::class)
        ->add('description', TextareaType::class)
        ->add('status', ChoiceType::class, [
            'choices' => [
                true => 'Active',
                false => 'Inactive'
            ]
        ])
        ->add('created', DateTimeType::class)
    ;
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'data_class' => Notes::class,
    ]);
}
}
php
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-08-22 14:56:08 +0000 UTC

计数器是否增加了 10 的倍数?[关闭]

  • 0
关闭。这个问题需要澄清或补充细节。目前不接受回复。

想改进这个问题?通过编辑此帖子添加更多详细信息并澄清问题。

2年前关闭。

改进问题

当输入的字符数为 10 时,如何为文本字段创建一个计数器,该计数器增加一?

javascript
  • 2 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-08-06 15:51:01 +0000 UTC

如何正确配置虚拟主机的配置?

  • 0

www.example.ru:8096上有一个正在运行的 docker 容器。如何正确配置 Apache 配置,以便可以在 service.example.ru 访问此容器

apache
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-05-27 11:39:46 +0000 UTC

如何正确验证 Vue 表单?

  • 0

我需要进行表单验证。

  1. 创建任务时,至少 10 个字符。红色边框。

在此处输入图像描述

  1. 正确时为绿色

在此处输入图像描述

  1. 并且在输入正确的值之前,该按钮不会处于活动状态。

在此处输入图像描述

jsfiddle代码在这里

            Vue.component('task-element',{
        props: [ 'task' ],
        data : function () {
           var d = {seconds_elapsed: null}; 
           return d;
        },
        methods: {
           timer() {
              this.seconds_elapsed = (Date.now() - this.task.startTime) / 1000 | 0;
              setTimeout(this.timer, 1000);
           }
        },
        created() {
           if (!this.task.startTime)
              this.$set(this.task, 'startTime', Date.now());
           this.timer();
        },
        template : `
        <li>
        <label :class="{ islong: task.text.length >= 15 }">
           <input type="checkbox" v-model="done">
           <span>{{ task.text }}</span>
           <small>{{ seconds_elapsed }} seconds ago</small>
        </label>
        <button v-if="task.done" @click="$emit('delete')">delete</button>
        </li>`,
        computed: {
           done: {
              get() {
              return this.task.done;
              },
              set(done) {
              this.$emit('update', { done });
              },
           },
        },
        });

        new Vue({
        el: '#app',
        data: {
           newTodo: '',
           todos: [
              { id: 1, text: 'Task 1', done: false },
              { id: 2, text: 'Task 2', done: false },
              { id: 3, text: 'Task 3', done: true },
           ],
           data_is_loaded: true,
        },
        methods: {
           addTodo() {
           if(this.newTodo.length > 10) {
              const text = this.newTodo;
              if (text.length) {
              this.todos.push({
                 id: 1 + Math.max(0, ...this.todos.map(n => n.id)),
                 text,
                 done: false,
              });
              this.newTodo = '';
              } else {
              alert('empty');
              }
           }},
        },
        });
vue.js
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-05-22 12:16:21 +0000 UTC

如何为已完成的任务添加删除按钮?

  • 0

如何仅为已完成的任务添加删除按钮?

        Vue.component('task-element',{
      props : ['task'],
      data : function () {
        var d = {seconds_elapsed: null}; 
        return d;
      },
      template : `<li>
          <label :class='{islong:task.islong}'>
            <input type="checkbox"
              v-on:change="toggle(task)"
              v-bind:checked="task.done">
            <span>
              {{ task.text }}
            </span>
            <small>
              {{ seconds_elapsed }}
            </small>
          </label>
        </li>`,
    });

    new Vue({
      el: "#app",
      data: {
        newTodos: '',
        todos: [{ text: "Задача", done: false, islong: false}],
        data_is_loaded: true,
      },
      methods: {
        addTodo (todo) {
            if(this.newTodo.length > 10) {
            this.todos.push({text: todo, done: false, islong: true})
            this.newTodo = ''
    }},
        toggle: function(todo){
          todo.done = !todo.done
        },
      }
    })

编码

vue.js
  • 2 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-11-22 10:52:35 +0000 UTC

如何制作 BEM 列表

  • -1
 <nav>
  <ul>
    <li><a href="#">О Нас</a></li>
    <li><a href="#">Услуги</a></li>
    <ul class="SubMenu">
      <li><a href="#">Ссылка 1</a></li>
      <li><a href="#">Ссылка 2</a></li>
    </ul>
    <li><a href="#">Вакансии</a></li>
    <li><a href="#">Нововти</a></li>
    <li><a href="#">Соглашение</a></li>
  </ul>
</nav>

如何正确设计 BEM 类。

html
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-07-24 12:12:37 +0000 UTC

看不懂 JS 任务

  • 1

我不明白为什么结果是8,请解释一下。

var a = 1,x;
x = ++a + ++a;
x +=a;
console.log(x); // 8

javascript
  • 1 个回答
  • 10 Views
Martin Hope
IlyaDrummer
Asked: 2020-04-28 23:33:36 +0000 UTC

在数组中添加两个元素并返回结果?[关闭]

  • 0
关闭 这个问题是题外话。目前不接受回复。

仅当您在提出问题之前尝试自己解决问题时,才允许将学习问题作为问题。请编辑问题并指出究竟是什么导致您难以解决问题。例如,请提供您在尝试解决问题时编写的代码

3年前关闭。

改进问题

有一个带有数字的数组。
arr = [1,5,23,54,123,54]


您需要添加每两个数字并打印结果:
1 + 5 = 6
23 + 54 = 77
等。

结果应显示在由空格分隔的行中:
6 77 等。

javascript
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5