我想使用JSON发送大字节数组(这个问题启发了我),为了减少开销,我想使用base128编码(实际上可以产生有效的json字符串)。但不幸的是,我无法找到一些在JS中进行转换的过程。我将发布过程作为对此问题的答案,但是可能是某个过程较短的人,或者是在JSON中有效发送二进制数据的更好的主意。
让我们看下面的例子:
Q1:为什么0这里输出?这是什么意思?
var a = 7;
console.log(a.constructor()); // prints 0 (Why?)Run Code Online (Sandbox Code Playgroud)
问题2:何时typeof a和typeof 7两者都是数字,为什么a.constructor()运行而7.constructor()没有?
var a = 7;
var bool = typeof a === typeof 7;
console.log(a.constructor()); // 0
console.log((++a).constructor()); // 0
console.log(7.constructor()); // SyntaxError: Invalid or unexpected token
console.log(++a.constructor()); // ReferenceError: Invalid left-hand side expression in prefix operationRun Code Online (Sandbox Code Playgroud)
我将id作为参数传递给javascript函数,因为它来自UI,它是零填充的.但它似乎有(可能)"奇怪"的行为?
console.log(0000020948); //20948
console.log(0000022115); //9293 which is 22115's octal
console.log(parseInt(0000022115, 10)); // 9293 which is 22115's octal
console.log(0000033959); //33959
console.log(20948); //20948
console.log(22115); //22115
console.log(33959); //33959
Run Code Online (Sandbox Code Playgroud)
我怎样才能确保它们解析到正确的数字呢?(十进制)
编辑:
只是让它更清楚:
这些数字来自服务器并且是零填充字符串.我正在为每个人制作一个删除按钮.
喜欢:
function printDelButton(value){
console.log(typeof value); //output string
return '<a href="#" onclick="deleteme('+value+')"><img src="images/del.png"></a>'
}
and
function printDelButton(value){
console.log(typeof value); //output numeric
console.log(value); //here output as octal .... :S
}
Run Code Online (Sandbox Code Playgroud)
我尝试过:__CODE__仍然解析为Octal
我使用 docker-compose 并发现以下问题:
当我更改代码并想要重建我使用的泊坞窗时
docker-compose stop
docker-compose build
Run Code Online (Sandbox Code Playgroud)
然后我想通过以下方式运行系统:
docker-compose up
Run Code Online (Sandbox Code Playgroud)
但是,除了旧版本之外,不会运行新版本的代码/容器。该怎么办?
我在这个库中使用打字稿。我在文件中有以下代码HomePage.vue:
<template>
<div>Write something x: <input v-model="someName" type="text"></div>
</template>
<script lang="ts">
import { Component, Model, Vue } from "vue-property-decorator";
@Component
export default class HomePage extends Vue {
@Model() someName: string;
}
</script>
Run Code Online (Sandbox Code Playgroud)
编译后,在浏览器中运行并在输入框中输入一些内容,我在 chrome 控制台中得到以下 vue 警告:
[Vue 警告]:避免直接改变 prop,因为每当父组件重新渲染时,值都会被覆盖。相反,根据道具的值使用数据或计算属性。道具被变异:“someName”
知道如何解决这个问题吗?
我正在使用JavaScript编写一个小程序。基本上,我想使用Promise和fetch从两个文本文件中提取文本。但是,我不知道如何从文件中获取实际的文本。这是我当前的代码。
sample.txt
this is
a sample
text file.
Run Code Online (Sandbox Code Playgroud)
sample2.txt
this is
the second
sample file.
Run Code Online (Sandbox Code Playgroud)
index.js
function getSampleText() {
Promise.all([
fetch('sample.txt'),
fetch('sample2.txt')
]).then(allResp => {
let sampleResp = allResp[0];
let sample2Resp = allResp[1];
console.log(sampleResp);
console.log(sample2Resp);
})
}
Run Code Online (Sandbox Code Playgroud)
这是应许...我该如何从中得到建议?
我有以下页面
section {
height: 1000px;
background: yellow;
margin: 50px;
}Run Code Online (Sandbox Code Playgroud)
<section id="one">Section one</section>
<section id="two">Section two</section>Run Code Online (Sandbox Code Playgroud)
如果用户来自包含哈希之后的节ID的链接,则仅使用html/css可以仅显示一个节
?
嗨,这是我的API
// --- API
// Replace ./data.json with your JSON feed
fetch('http://127.0.0.1:8000/cars/')
.then(response => {
return response.json()
})
.then(data => {
// Work with JSON data here
//-- go to array named "results"
obj1 = data.results
console.dir(obj1)
<...>
Run Code Online (Sandbox Code Playgroud)
这是我的API输出。一些带有对象和随机数据的数组。
[{{id“:3,” name“:” Audi“,” price“:11},{” id“:2,” name“:” Mercedes“,” price“:22},{” id“: 1,“名称”:“宝马”,“价格”:99},{“ id”:4,“名称”:“ Trabant”,“价格”:113}]
我想通过对象的键将对象循环到JavaScript中的不同数组中。例如,以便Chart.js可以将其作为标签来处理。
例
[“奥迪”,“梅赛德斯”,“宝马”,“特拉巴特”]
所以我尝试了这三种不同的方法来完成这项工作
Object.keys
Object.values
Object.entries
Run Code Online (Sandbox Code Playgroud)
我也尝试过循环
// --- LOOP
var arr = obj1
for (var i = 0; i < arr.length; i++) {
console.dir(arr[i]);
}
console.dir(arr)
Run Code Online (Sandbox Code Playgroud)
但是我只用循环摆脱了 …
let foo = {};
const key1 = 'a';
const key2 = 'b';
const key3 = 'c';
foo[key1][key2][key3] = [1, 2];
Run Code Online (Sandbox Code Playgroud)
当我尝试做类似的事情时,我得到:
Uncaught TypeError: Cannot read property 'b' of undefined
Run Code Online (Sandbox Code Playgroud) 以编程方式单击 li 元素“过去 30 天”(控制台)
<div class="ranges">
<ul>
<li>Today</li>
<li >Yesterday</li>
<li>Last 7 days</li>
<li>Last 30 days</li>
<li class="">This month</li>
<li>Custom Range</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试了很多方法但失败了
喜欢。
$('#Last 30 days').trigger('click');
$('#Last 30 days').click();
Run Code Online (Sandbox Code Playgroud)
我是 JavaScript 新手请帮帮我
javascript ×7
html ×2
annotations ×1
arrays ×1
asynchronous ×1
chart.js ×1
click ×1
css ×1
deployment ×1
docker ×1
fetch-api ×1
html-lists ×1
json ×1
loops ×1
numbers ×1
promise ×1
typescript ×1
vuejs2 ×1