小编WeS*_*eSt的帖子

Angular2嵌套*ngFor

我使用一个数组来存储一个组对象列表和一个轻量级对象列表.我想在html中显示第一组,并向该组显示所有连接的灯.之后,下一组和相关的灯等等......

<div>
  <ul>
    <li *ngFor="let group of hueGroups">
      {{group.name}}
      <li *ngFor="let light of hueLights; let i = index">
      {{hueLights[group.lights[i]].name}}
    </li>
  </ul>
</div>



export class AppComponent implements OnInit {
  hueGroups:any[];
  hueLights:any[];

  constructor(){
    this.hueGroups = [];
    this.hueLights = [];
  }

  listAllGroups(){
   for(var g in MyHue.Groups){ //MyHue.Groups returen an array with objects
    console.log(g);
    console.log(MyHue.Groups[g].name);
    for(var id:number = 0; id < MyHue.Groups[g].lights.length; id++){
      console.log("LightID:" + MyHue.Lights[MyHue.Groups[g].lights[id]].name); // Returns the name of the Lights
    }
    this.hueGroups.push(MyHue.Groups[g]);
  }

  listAllLights(){
   for(var l in MyHue.Lights){ //MyHue.Lights returns an …
Run Code Online (Sandbox Code Playgroud)

nested ngfor angular

5
推荐指数
1
解决办法
1万
查看次数

在玩笑中模拟动态 html 元素

我想为一个 utils 方法编写一个测试。在该方法中,我通过 id 获取一个 html 元素,然后更改元素的颜色。问题是该元素仅在单击按钮后可用。我如何模拟元素?

UtilListItem.js

import variables from '../stylesheets/Variables.scss';

export function activeListItem(props){
 let listItem = document.getElementById(props.id);
 listItem.style.backgroundColor = variables.whiteGray;
 return listItem;
}
Run Code Online (Sandbox Code Playgroud)

UtilListeItem.test.js

it('check if the correct color is set for the acitve list item', () => {
  let props = {id:'123'}
  const listItem = activeListItem(props);
  expect(listItem.style.backgroundColor).toBe('#ededed');
});
Run Code Online (Sandbox Code Playgroud)

错误

TypeError: Cannot read property 'style' of null
Run Code Online (Sandbox Code Playgroud)

javascript mocking reactjs jestjs

5
推荐指数
2
解决办法
2万
查看次数

NodeJs 需要 Apache 吗?

在我的本地机器上,我已经建立了一个像教程中提到的 web 项目。我已经安装了 XAMPP 并使用 MySQL 和 Apache 来运行我的 Node.JS 后端。现在我将使用外部服务器来托管该项目并使其通过 Internet 可用。

所以我必须设置服务器,我想知道为什么我需要 Apache(来自 XAMPP)来运行 Node.JS 后端?我认为 node.js 本身就是一个网络服务器?那么使用 XAMPP 再次设置外部服务器是一个聪明的主意吗?

当我想通过 URL 启动 index.html 时,我是否也可以使用 node.js 执行此操作?

javascript mysql apache webserver node.js

4
推荐指数
1
解决办法
2524
查看次数

通过Node.js访问mysql数据库的最佳实践

目前,我正在运行带有express的节点js后端,以从客户端访问mysql数据库。现在,我正在重构代码,将来自客户端的“胖”东西也放到nodejs后端。我的第一个想法是保持快速路线如:

模块A:

router.get('/getitem/:code',(req, res) => {
let sql = `SELECT * FROM xyz WHERE CODE = ${req.params.code}`;
let query = db.query(sql, (err, result) =>{
  if(err == null){
    console.log(result);
    res.send(result);
  }else{
    console.log("Error by getting item from db: " + err);
    throw err;
  }
 });
});
Run Code Online (Sandbox Code Playgroud)

并根据需要通过其他模块通过http请求进行访问:

function geodataByLocationcode(locationcode){
 request({
  method: 'GET',
  url: "http://" + server_connection.host + ":" + server_connection.port + '/getitem/' + locationcode,
  headers: {
    "Content-Type": "application/json"
  }
 },function(error, response, body){
 ....
 }
Run Code Online (Sandbox Code Playgroud)

但这是执行此操作的最佳方法吗?还是因为请求现在也来自后端,以更直接的方式访问数据库会更好?

mysql node.js

2
推荐指数
1
解决办法
5149
查看次数

http 快速路由的混合内容错误

我在我的机器上运行本地 Node js 服务器,并为其提供一个ngrok.io域。

如果我在网络浏览器中本地运行它,localhost:3000则http://1234.ngrok.io一切正常。如果我调用它,httpS://1234.ngrok.io我会收到错误

Mixed Content: The page at 'https://1234.ngrok.io/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://localhost:3000/calculation'. This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)

由于路由不是http造成的。我怎样才能解决这个问题?

这是我的node.js 上的app.js

const express = require('express');
const app = express();
const https = require('https');
const http = require('http');
const fs = require('fs');

app.use('/', express.static(__dirname + '/../Client'));

var options = {
  key: fs.readFileSync('./https_certificate/client-key.pem'),
  cert: fs.readFileSync('./https_certificate/client-cert.pem')
};

app.listen(server_connection.port, () …
Run Code Online (Sandbox Code Playgroud)

https routes http node.js express

1
推荐指数
1
解决办法
5695
查看次数

标签 统计

node.js ×3

javascript ×2

mysql ×2

angular ×1

apache ×1

express ×1

http ×1

https ×1

jestjs ×1

mocking ×1

nested ×1

ngfor ×1

reactjs ×1

routes ×1

webserver ×1