阅读一篇有关 Angular 变更检测机制的文章时,我遇到了以下打字稿代码:
detach(): void { this._view.state &= ~ViewState.ChecksEnabled; }
Run Code Online (Sandbox Code Playgroud)
我一直在努力理解那行代码。
我知道这个~技巧以及它如何与 一起使用indexOf()。我发现很难用位来理解,但记住它可以被替换为-(x+1)-1 假值,这样就更容易了。
它似乎ViewState.ChecksEnabled是一个布尔值,所以~ViewState.ChecksEnabled给出 -(0 + 1) 或 -(1 + 1)
然后通过&=按位赋值(?)我们得到
this._view.state = this._view.state & -1; // or -2
Run Code Online (Sandbox Code Playgroud)
这里有什么技巧呢?
我开发一个 Web 应用程序(前面是 Angular,后面是 Node/Express/Mongo)已经有几个月了。
我在 localhost:4200 上运行 Angular,在 localhost:3000 上运行 Node
我们团队中的一些人在其计算机上运行的虚拟机中运行后端。
为了使应用程序在这两种情况下都能工作,我们编辑了 Windows 主机文件,使应用程序指向正确的位置(虚拟机或本地计算机的背面)
127.0.0.1 mysite
使用 VM 的开发人员将其 VM 的 IP 更改为 127.0.0.1。
一切都很顺利。
几天前,我们公司在每台 PC 上安装了 Bitlocker,我相信这会导致我们的设置因不使用 VM(不受 Bitlocker 限制)的每个人而中断
在本地主机上工作的人们开始从前端应用程序接收:
选项http://mysite:3000/auth/login 426(需要升级)
这些请求甚至没有到达节点服务器。看起来他们被重定向到 websocket 服务器?
如果我将请求更改为目标 localhost:3000,应用程序会再次运行,但我们会丢失在虚拟机上工作的人员的设置。(因此,如果我们每次都需要更改基本 url,那么提交代码就会变得很烦人)
我可以为每个案例创建一个环境,但它不干净,我想知道为什么它突然坏了。
我有一个简单的 Todo/作者/评论
Todo has_many comments
Comment belongs_to Todo
Todo belongs_to Author
Author has_many todos
Author has_many comments
Comment belongs_to Author
Run Code Online (Sandbox Code Playgroud)
如果我像这样渲染 todo_view.ex:
def render("todo.json", %{todo: todo}) do
%{id: todo.id,
title: todo.title,
description: todo.description,
date: todo.date,
author: author_json(todo.author)}
end
defp author_json(author) do
%{name: author.name}
end
Run Code Online (Sandbox Code Playgroud)
当我访问时一切正常/api/todos,/api/comments
但是如果我想添加待办事项的评论列表:
def render("todo.json", %{todo: todo}) do
%{id: todo.id,
title: todo.title,
description: todo.description,
date: todo.date,
author: author_json(todo.author),
comments: render_many(todo.comments, CommentView, "comment.json")}
end
Run Code Online (Sandbox Code Playgroud)
我在 comment_view.ex 中收到 KeyError
键:名称未在以下位置找到:#Ecto.Association.NotLoaded
def render("comment.json", %{comment: comment}) do
%{id: …Run Code Online (Sandbox Code Playgroud) 基于如下所示的数组:
var members = [
{name: "john", team: 1},
{name: "kevin", team: 1},
{name: "rob", team: 2},
{name: "matt", team: 2},
{name: "clint", team: 3},
{name: "will", team: 3}
];
Run Code Online (Sandbox Code Playgroud)
我需要为每个团队创建一个无序列表.
可以直接用ngRepeat和过滤器完成吗?
或者更容易将数组重新组织成一个包含成员列表的团队数组?
var teams = [
{id: 1, members: ["john", "kevin"]},
{id: 2, members: ["rob", "matt"]},
{id: 3, members: ["clint", "will"]}
]
Run Code Online (Sandbox Code Playgroud)
嵌套的ngRepeat很容易实现,但是如何以简单/聪明的方式从第一个数组转到这个数组呢?
注意:该数组不是来自数据库,而是来自html表.所以它只是一个简单的成员列表.
function MyController() {
this.members = [
{name: "john", team: 1},
{name: "kevin", team: 1},
{name: "rob", team: 2},
{name: "matt", team: 2},
{name: "clint", team: …Run Code Online (Sandbox Code Playgroud)angular ×2
angularjs ×1
arrays ×1
bitlocker ×1
elixir ×1
function ×1
javascript ×1
node.js ×1
typescript ×1