我对JS中的Set类型感到困惑。如果使用未正确初始化的Set创建变量,则不能再使用它(作为Set或原始类型)。在控制台中尝试:
let someSet = new Set(4);
/* Uncaught TypeError: number 4 is not iterable (cannot read property Symbol(Symbol.iterator))
at new Set (<anonymous>)*/
someSet
// Uncaught ReferenceError: someSet is not defined
let someSet = new Set([4])
// Uncaught SyntaxError: Identifier 'someSet' has already been declared
someSet
// Uncaught ReferenceError: someSet is not defined
let someSet = 'ho-ho-ho'
// Uncaught SyntaxError: Identifier 'someSet' has already been declared
someSet = 'ho-ho-ho'
// Uncaught ReferenceError: someSet is not defined
Run Code Online (Sandbox Code Playgroud)
你能解释一下为什么吗?见屏幕:
我创建了一个加密对象,如下所示:
var crypto = {
encrypt: function(s) {
}
};
crypto.encrypt("cat");Run Code Online (Sandbox Code Playgroud)
我会收到以下错误
未捕获的TypeError:
crypto.encrypt不是函数
var crypt = {
encrypt: function(s) {
}
};
crypt.encrypt("cat");Run Code Online (Sandbox Code Playgroud)
这会工作。我意识到已经有一个内置crypto对象,因此无法识别我定义的加密对象。
我的理解是,稍后声明的变量将覆盖之前声明的变量。
例如,当我创建两个对象时,如下所示:
var test = {
testing2: function() {
return "there";
}
}
var test = {
testing: function() {
return "hey";
}
}
test.testing2()Run Code Online (Sandbox Code Playgroud)
然后我打电话给我,test.testing2()因为第二个测试变量遮盖了第一个测试变量,所以引发了类似的错误。因此,如果变量影子可用于自创建变量,那么为什么不加密加密货币呢?是否存在这样的情况,即预定义对象的优先级始终较高,因此任何自行创建的对象都不会遮盖窗口对象。我对此表示感谢。谢谢!
所以我试图使用这个https://github.com/seeden/react-facebook作为我的混合反应应用程序的一部分。但是,当我将代码复制并粘贴到我的项目中时,它给了我一个错误
import React, {Component } from 'react';
import { FacebookProvider, Page } from 'react-facebook';
//import {createBottomTabNavigator, createAppContainer} from 'react-
navigation';
export default class Home extends Component {
render(){
//const { navigate } = this.props.navigation
return (
<FacebookProvider appId="2319566588264121">
<Page href="https://www.facebook.com/somepage/" tabs="timeline"
/>
</FacebookProvider>
);
}
}
Run Code Online (Sandbox Code Playgroud)
这个想法是在我的应用程序屏幕上显示一个 facebooks 页面提要。但是我收到这个错误:
Invariant Violation: View config not found for name div. Make sure to start component names with a capital letter.
This error is located at:
in div (created …Run Code Online (Sandbox Code Playgroud) 我正在尝试验证PersonPaymentDetails模型中的sortCode字段,但我的视图无法验证StringLength(6).如果我提交长度为1的表单,则表示错误验证成功.
我在这里做了一些根本错误的事吗?
/* [CONTROLLER] */
public class PersonController : Controller
{
[HttpGet]
[Route("person/paymentDetails/create/{personId?}")]
public ActionResult PaymentDetailsCreate(int? personId)
{
if (personId == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Person person = db.People.Find(personId);
if (person == null)
{
return HttpNotFound();
}
PersonPaymentDetailsViewModel personPaymentDetailsVM = new PersonPaymentDetailsViewModel();
personPaymentDetailsVM.SetPerson(person);
return View(personPaymentDetailsVM);
}
[HttpPost]
[Route("person/paymentDetails/create")]
public ActionResult PaymentDetailsCreate(PersonPaymentDetailsViewModel personPaymentDetailsVM)
{
if (ModelState.IsValid)
{
/* should not be entering here with sortCode = 123, as not 6 characters in length */
return Content("No errors: |" + …Run Code Online (Sandbox Code Playgroud) 我的React项目中有一个数组.就像是 :
state = {
cats : [
{cid : 1 , value : 1}
{cid : 2 , value : 3}
{cid : 3 , value : 4}
],
curpage : 3
}
Run Code Online (Sandbox Code Playgroud)
现在我想要的是用destructring 获取nth item数组cats.我试过了
const { cat : {cats[id]} } = this.state;
Run Code Online (Sandbox Code Playgroud)
要么
const { cats[id] } = this.state;
Run Code Online (Sandbox Code Playgroud) 我正在尝试根据路线加载多个帐户的 twitter 时间线。例如,如果有人请求特定页面,则页面上会加载特定帐户的 Twitter 时间线。
我尝试使用一个名为的插件,vue-tweet-embed但它根本不起作用,所以,我尝试了旧方法。我widgets.js在我的主 HTML 文件中包含了 twitter ,并尝试使用静态代码包含时间轴,如下所示。
静态代码
<a class="twitter-timeline" href="https://twitter.com/Google?ref_src=twsrc%5Etfw">Tweets by Google</a>
Run Code Online (Sandbox Code Playgroud)
现在,我想根据变量显示多个帐户的 Twitter 时间线。我的变量是一个对象的属性,因此,这是我尝试使用的代码。请注意,上面给出的静态代码即使在 Vue 组件中也能工作。
动态代码
<a class="twitter-timeline" data-height="500px" v-if="isLoading===false" :href="'https://twitter.com/'+service.twitter_handle+'?ref_src=twsrc%5Etfw'"></a>
Run Code Online (Sandbox Code Playgroud)
但是动态的不起作用。我检查了检查元素,代码生成的标记非常好。但它什么也没显示。当代码是动态的时,它不会加载 Twitter 时间线。
这是生成的标记:
<div class="card-body">
<a data-height="500px" href="https://twitter.com/Google?ref_src=twsrc%5Etfw" class="twitter-timeline"></a>
</div>
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题,自过去 3 小时以来一直在尝试解决此问题,但似乎没有任何效果。
const errorMessage = "some error message";
const fieldName = "the field name";
const newFieldRules = [{
custom: false,
errorMessage: errorMessage,
fieldName: fieldName,
validatorName: `digits`
},
{
custom: false,
errorMessage: errorMessage,
fieldName: fieldName,
validatorName: `min`
},
{
custom: false,
errorMessage: errorMessage,
fieldName: fieldName,
validatorName: `max`
}
];Run Code Online (Sandbox Code Playgroud)
我需要创建上面的数组.如您所见,所有对象中的属性都相同.
有没有办法改进这段代码以避免重复?
我正在做本机应用程序的反应。我收到如下 json 响应。
[
{
id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
},
{
id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
},
{
id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
},
{
id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'
}
]
Run Code Online (Sandbox Code Playgroud)
我必须检查所有value属性是否为空。如果全部都是空的,我必须做一些其他动作,否则条件其他动作。
const emptyValues = sortedData.map(value => value.key);
console.log('emptyValues data', emptyValues);
Run Code Online (Sandbox Code Playgroud) 如果我有2个数组(properties和data):
properties = [name, height, weight, zone];
data = [
['Luke Skywalker', 123, 112, 'B'],
['Jawa', 12, 8, 'B'],
['Hutt', 200, 999, 'C']
];
Run Code Online (Sandbox Code Playgroud)
并且我想创建一个对象数组(statistics):
statistics = [{
name: 'Luke Skywalker',
height: 123,
weight: 112,
zone: 'B'
},
{
name: 'Jawa',
height: 12,
weight: 8,
zone: 'B'
}, {
name: 'Hutt',
height: 200,
weight: 999,
zone: 'C'
}
];
Run Code Online (Sandbox Code Playgroud)
通常,我只会使用map over data[],创建一个temp对象,然后将其推入statistics[]。
但是由于我知道所有其他条目data都具有相同的维度和数据类型。我也知道从properties到一对一的映射data。javascript中是否有内置函数,该函数以一对一映射输出对象数组?相似 …
In Javascript, Node.js I can generate with https://www.npmjs.com/package/uuid package a 15 digit length "random" string. Is it possible it with Swift?
Like this: 802128100247740
const uuidv4 = require("uuid/v4");
tempUserUuid = uuidv4();
Run Code Online (Sandbox Code Playgroud) javascript ×8
ecmascript-6 ×3
arrays ×2
react-native ×2
api ×1
asp.net-mvc ×1
c# ×1
model ×1
node.js ×1
object ×1
reactjs ×1
swift ×1
twitter ×1
uuid ×1
vue.js ×1
vuejs2 ×1