Addison

7135 经验值

估计可以通过如下改善一点:
const todoIndex = todos.findIndex((todo) => todo.id === id);
todos.splice(todoIndex,1);

知识点摘要:
An arrow function does not have its own this; the this value of the enclosing execution context is used.
Arrow functions do not have a prototype property.
(1)Arrow functions cannot be used as constructors and will throw an error when used with new.
(2) Since arrow functions do not have their own this, the methods call() or apply() can only pass in parameters. thisArg is ignored.
(3) Arrow functions do not have their own arguments object. Thus, arguments is simply a reference to the arguments of the enclosing scope.
(4) arrow functions cannot be used as generators.

详情查看: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

<body>
<div class="container">
    <form class="add-comment">
        <textarea class="comment-text"></textarea><br>
        <button type="button" class="btn btn-primary" value="submit">Post Comment</button>
    </form>
    <div class="comment"></div>
</div>
<script>
    const addCommentForm = document.querySelector('.add-comment');
    const textarea = document.querySelector('.comment-text');
    const commentDiv = document.querySelector('.comment');
    const user = 'Mary';

    addCommentForm.addEventListener('submit', function (event) {
        event.preventDefault();
        const newConmment = textarea.value.trim();
        if (newConmment)
        {
            commentDiv.innerHTML = `
            <div class=" comment-header">${user}</div>
            <div class="comment-body">${textarea.value}</div>
            `
            textarea.value = ``;
        }
    })
</script>
</body>

文本框内容不能成功提交。。。

我的还是实现不了哦
尴尬C:\Users\janicerant\Desktop\webpack-learning>webpack
C:\Users\janicerant\Desktop\webpack-learning\webpack.config.
js:23

},
 ^

SyntaxError: Invalid or unexpected token

at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at requireConfig (C:\Users\janicerant\AppData\Roaming\np

m\node_modules\webpack\bin\convert-argv.js:97:18)

{

            test:/\.js$/,
            loader:"babel-loader",
            exclude:/node_modules/,
        }
    ]
},
babel:{
    preset: ['es2015','stage-0'],
    plugins: ['trsnsform-runtime']

}
};

箭头函数的特点第三个是什么呀

比如有一个 Model 类名称为UserPost,那么其数据表默认蛇形名称为: user_posts.在程序语言中,蛇形名称也常用于变量/方法的命名,与驼峰相对应.

@JellyBool, 谢谢。我从How to use Transformer in one to many relationship. #1054找到了更好的解决方案。
先上代码:

DepartmentTransformer

class DepartmentTransformer extends TransformerAbstract
{
    public function transform($department)
    {
        return [
            'id' => $department['id'],
            'name' => $department['name'],
            'level' => $department['level'],
            'parent_id' => $department['parent_id']
        ];
    }
}

RolesTransformer

class RolesTransformer extends TransformerAbstract
{
    public function transform($role)
    {
        return [
            'name' => $role['name'],
            'slug' => $role['slug'],
            'description' => $role['description'],
            'level' => $role['level']
        ];
    }

}

UserTransformer

class UserTransformer extends TransformerAbstract
{
    protected $defaultIncludes = ['departments','roles'];


    public function transform($user)
    {
        return [
            'id' => $user['id'],
            'name' => $user['name'],
            'email' => $user['email'],
            'phone' => $user['phone'],
        ];
    }


    public function includeDepartments(User $user)
    {
        $dept  = $user->departments;

        return $this->collection($dept, new DepartmentTransformer());
    }


    public function includeRoles(User $user)
    {
        $rl = $user->roles;

        return $this->collection($rl, new RolesTransformer());
    }
}

然后,我在 Controller 里面调用

$user = User::where('email','=',$input['email'])->with('departments')->with('roles')->get();

return $this->response->collection($user, new UserTransformer());

得到如下返回

           "data": {
            {
                "id": 43,
              "name": "test7",
              "email": "test7@foxmail.com",
              "phone": "18679152257",
              "departments": {
                "data": {
                  {
                      "id": 1,
                    "name": "业务一部",
                    "level": 1,
                    "parent_id": 0
                  }
                }
              },
              "roles": {
                "data": {
                  {
                      "name": "agent",
                    "slug": "agent",
                    "description": "业务员",
                    "level": 1
                  }
                }
              }
            }
          }