尝试使用常规功能而不是箭头功能,应该修复它!
UsersSchema.pre('save', function (next: any) {
if (!this.isModified('password')) return next();
this.password = encrypt(this.password, 10);
next();
});
这是双向数据绑定或商店概念在许多新的JavaScript框架中使用的地方之一,这对您来说非常有用...
因此,如果您使用< a href =“ https://en.wikipedia.org/wiki/angular_(web_framework)” rel =“ noreferrer”> angular href =“ https://en.wikipedia.org/wiki/wiki/react_(web_framework)” rel =“ noreferrer”> react 或任何其他有双向数据绑定或存储概念的其他框架,此问题是简单地为您修复,因此,简单地说,您的结果是在第一阶段
,因此您有 result =未定义的
在收到数据之前,一旦获得结果,它将被更新并分配给新值AJAX调用的响应...
但是如何在纯JavaScript或例如,正如您在这个问题中提出的那样?
您可以使用回调,承诺并最近可观察到为您处理。例如,在承诺中,我们具有一些功能,例如 success()
或 then()
,当您的数据准备就绪时将执行。可观察到的回调或 subscribe 函数相同。
例如,在您正在使用jQuery的情况下,您可以做类似的事情:
$(document).ready(function(){
function foo() {
$.ajax({url: "api/data", success: function(data){
fooDone(data); // After we have data, we pass it to fooDone
}});
};
function fooDone(data) {
console.log(data); // fooDone has the data and console.log it
};
foo(); // The call happens here
});
有关更多信息,研究承诺和观察物是做这种异步工作的新方法。
这是一个热图方法:
每一行都显示模型的预测,每列都是一个实例预测,颜色代表预测的值。
import plotly.express as px
fig = px.imshow(list(data.values()), y = list(data.keys()))
fig.show()
其次,您可以通过比较它们预测相同的速率来彼此比较模型同一实例的类别。
import pandas as pd
df = pd.DataFrame(data)
rate_of_same_prediction = df.apply(lambda x:[ (x== df[ col ]).mean() for col in df.columns], axis=0)
rate_of_same_prediction.index = rate_of_same_prediction.columns
fig = px.imshow(rate_of_same_prediction)
fig.show()
这里的列和行都代表您的模型。
Dt1 = Dt1.AsEnumerable()
.GroupBy(r => new { filename = r.Field<string>("filename1"), filesize = r.Field<string>("filesizeinkb") })
.Where(g => g.Count() == 1)
.Select(g => g.First())
.CopyToDataTable();
这将丢弃任何一个以上项目的组,然后从其余的第一个(也是唯一的)项目中获取。
区分参数的典型方法是提供一个替代的静态函数来创建实例。这就是某些本地课程的完成方式。例如, array
具有 array.of
, array.from
和 object
code> object.fromentries , object.create
,...
如果我们遵循该模式,则您的示例代码可能会变为:
class MyClass {
static fromFile(path, isPublic=true) {
// read key file
const content = ...
// Pass the appropriate arguments to constructor
return isPublic ? new this(null, content) : new this(content);
}
static fromSize(size) {
// Create new key pairs based on the given size
const privateKey = ...
const publicKey = ...
return new this(privateKey, publicKey);
}
// Constructor is dumb: it has little logic
constructor(privateKey, publicKey) {
// If no public key is given, produce it from the private key
if (publicKey === undefined) {
if (privateKey === undefined) throw Error("must provide at least one key");
// Generate public key instance from private key
publicKey = ...
}
this.privateKey = privateKey ?? null; // turn undefined into null
this.publicKey = publicKey;
}
}
// Example calls:
let x = MyClass.fromFile("/testPublic.key");
let y = MyClass.fromSize(5);
let z = new MyClass("a", "b");
无法如 @Scheff的猫所述连接类。
解决方案是不要在 usb2can_driver 中使用QSerialport的继承。如果我想通过插槽(是第二类)连接QSerialport的信号,则必须在USB2CAN_DRIVER的构造函数中创建一个对象。
此对象允许使用信号/插槽机制。
简而
对于第二类(Canview)中的连接,我使用了此语法:
connect(u2c->port_USB2CAN,SIGNAL(readyRead()),this,SLOT(read_u2c()));
感谢Scheff的Cat,您的评论很有帮助。该解决方案正在起作用,但是如果有人看到非标准语法,请警告我。
您已经使用了 QuerySelector()
方法来访问DOM元素。此方法用于访问单元素。
querySelectorall()
方法用于访问与CSS查询匹配的所有元素。 querySelectorall()
方法返回 Nodelist 。
在此片段中,使用了 foreach
循环。
由于由 querySelectorall()
选择的Nodelist具有类似 array的结构结构在回调功能中
let tooltips = document.querySelectorAll('.toolhere + section');
document.addEventListener("mousemove", function(e) {
const posX = `${e.clientX + 3}px`;
const posY = `${e.clientY + 3}px`;
tooltips.forEach((tooltip) => {
tooltip.style.top = posY;
tooltip.style.left = posX;
});
});
.toolhere {
position: relative;
}
.toolhere+section {
opacity: 0;
width: fit-content;
position: fixed;
font-family: sans-serif;
background-color: #ECECEC;
color: #4D4E53;
border-radius: 5px;
padding: 4px 8px 4px 9px;
font-size: 12px;
transition: opacity .5s;
}
.toolhere:hover+section {
opacity: 1;
}
<div class="items">
<div class="sub-content">
<div class="iconsize toolhere">
<img src="https://media.istockphoto.com/photos/positive-man-celebrating-success-picture-id1221837116?k=20&m=1221837116&s=612x612&w=0&h=HfTeaCWySduic6zF3kC-jGjWq_JgQUc5BtBjdCzBQzU=" />
</div>
<section class="tooltip">this is tooltip</section>
</div>
<div class="sub-content">
<div class="content-name toolhere"></div>
<section class="tooltip">this is tooltip</section>
</div>
</div>
我想您正在尝试做类似以下操作:
class SomeClass {
obj = {
functionName: "add",
args: [10, 20],
};
add(a, b) {
return a + b;
}
invokeFunc() {
const { functionName, args } = this.obj;
return this[functionName](...args);
}
}
const instance = new SomeClass();
console.log(instance.invokeFunc());
由于可以从 this
对象访问要调用的函数,因此您可以调用它,并且 vrize(...)所有参数。
对于 async
函数,它是不是清楚地表明它是 async
函数。您可以在对象中具有类型
字段,并有条件地等待
该功能。
最好使用Bash数组,并在需要时加入CSV字符串:
#!/usr/bin/env bash
readarray -t listofusers < <(cut -d, -f4- file.csv | tr -d '"' | tr ','
cut -d,-f4- file.csv | tr -d'''| tr',$'\ n'| sort -u
是重要的位 - 它首先仅打印出CSV输入文件的第四和以下字段进入新线,然后对产生的用户名进行分类,然后删除使用 readarray
内置的输出的重复项。但是,您需要的个别要素。
\n' | sort -u))
IFS=,
printf "%s\n" "${listofusers[*]}"
cut -d,-f4- file.csv | tr -d'''| tr',$'\ n'| sort -u
是重要的位 - 它首先仅打印出CSV输入文件的第四和以下字段进入新线,然后对产生的用户名进行分类,然后删除使用 readarray
内置的输出的重复项。但是,您需要的个别要素。
我们可以使用
document> document.queryseleslect /a>选择我们的元素(如果只有一个),
但是在这种情况下,我们需要使用 querySelectorall
用于选择HTML中的所有广告元素
Web 我们可以使用 foreach
使用
foreach
您可以获取其他3个信息,
- 元素本身(您可以使用逻辑或console.log进行逻辑)
- 元素的索引
- 所有元素的数组
使用此顺序(元素,IndexOflement,arrayoflearts)
这是一个例子:
let unfilledAds = document.querySelectorAll(`.adsbygoogle[data-ad-status="unfilled"]`);
let successAds = document.querySelectorAll(`.adsbygoogle[data-ad-status="success"]`);;
/* not success */
unfilledAds.forEach((adElement) => {
/* your logic */
console.log(`❌ this Ad is not filled`, adElement);
});
/* success */
successAds.forEach((adElement) => {
console.log(`✅ this ad is visible to the user`, adElement);
});
<!-- fail -->
<ins data-ad-status="unfilled" class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-1714167228247329" data-ad-slot="8611448539" data-adsbygoogle-status="done"></ins>
<ins data-ad-status="unfilled" class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-1714167228247329" data-ad-slot="8611448539" data-adsbygoogle-status="done"></ins>
<!-- success -->
<ins data-ad-status="success" class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-1714167228247329" data-ad-slot="8611448539" data-adsbygoogle-status="done"></ins>
<ins data-ad-status="success" class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-1714167228247329" data-ad-slot="8611448539" data-adsbygoogle-status="done"></ins>
您还可以通过选择所有元素,然后做一个简单的话(检查结果)
来概括
[data-ad-status]
您也可以将此自定义的Google事件用于ADS https> https: //developers.google.com/publisher-tag/samples/ad-event-listeners 而无需重新发明车轮
,如果一段时间后的广告成功,它将起作用。
只需查看 docs 。
这里一个示例:
按名称组并应用示例
(在该组中随机n随机n),其中n是您所需的金额或该组的完整金额,例如:
out = df.groupby('NAME').apply(lambda g: g.sample(min(len(g), target_number_rows)))
否则,请使用第一个N或最后一个,例如:
out = df.groupby('NAME').head(target_number_rows)
# or...
out = df.groupby('NAME').tail(target_number_rows)
错误 - 无法将值插入列中
上述错误表明 null
col2 上有 null
。
使用下面的命令查看的架构“ test2_dedicated_pool”
表。
SELECT * from sys.schemas where name = “test2_dedicated_pool”
您可能没有在“ COL2”
上发现零约束。然后,只需尝试更改模式并删除无效约束即可。
我编写的以下示例显示了如何
这个工作示例是独立的。它将定义一个简单的请求对象,该对象使用窗口
xmlhttprequest
对象进行呼叫。它将定义一个简单的功能,以等待一堆诺言要完成。语境。该示例是查询 spotify web api 端点以搜索
播放列表
给定的查询字符串的对象:对于每个项目,一个新的承诺将发射一个块 -
executionBlock
,解析结果,根据结果数组安排一组新的承诺,即Spotifyuser
对象的列表,并在executionProfileBlock
ynchronChronical中执行新的HTTP调用。然后,您可以看到一个嵌套的承诺结构,该结构使您可以产生多个和完全异步的嵌套HTTP调用,并通过
Promise.all
从每个呼叫的每个子集中加入每个子集的结果。注意
最近的Spotify
搜索
API需要在请求标题中指定访问令牌:因此,您要运行以下示例,需要将访问令牌放在请求标题中:
我已经广泛讨论了此解决方案在这里。
The following example I have written shows how to
This working example is self-contained. It will define a simple request object that uses the window
XMLHttpRequest
object to make calls. It will define a simple function to wait for a bunch of promises to be completed.Context. The example is querying the Spotify Web API endpoint in order to search for
playlist
objects for a given set of query strings:For each item, a new Promise will fire a block -
ExecutionBlock
, parse the result, schedule a new set of promises based on the result array, that is a list of Spotifyuser
objects and execute the new HTTP call within theExecutionProfileBlock
asynchronously.You can then see a nested Promise structure, that lets you spawn multiple and completely asynchronous nested HTTP calls, and join the results from each subset of calls through
Promise.all
.NOTE
Recent Spotify
search
APIs will require an access token to be specified in the request headers:So, you to run the following example you need to put your access token in the request headers:
I have extensively discussed this solution here.
如何从异步电话中返回响应?