我正在努力在视图中输出随机字符串。
由于错误:
类型 '()' 不能符合 'View
我了解到 View 不是写下函数本身的合适位置。
我应该怎么做才能输出itemX.randomElement()和itemY.randomElement()?
struct SummaryView: View {
var avgValue = 1.5
var roundedKarvonenValue: Double
var itemX = ["A", "B", "C", "D", "E", "F", "G", "H"]
var itemY = ["I", "J", "K", "L", "M", "N", "O", "P"]
var body: some View {
ScrollView {
VStack(alignment: .leading) {
if workoutManager.averageHeartRate < roundedKarvonenValue {
print(itemX.randomElement()!)
} else {
print(itemY.randomElement()!)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试构建,纱线构建,但它向我展示了
yarn run v1.22.17
error Couldn't find a package.json file in "/home/darth/.config/nvim/plug-config"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Run Code Online (Sandbox Code Playgroud) 仅在safari浏览器中出现错误:
类型错误:未定义不是对象(评估“navigator.clipboard.writeText”)
我正在传递我当前的链接。可能是什么问题呢?
copyLink = e => {
e.preventDefault();
console.log(document.location.href)
navigator.clipboard
.writeText(document.location.href)
.then(() => {
this.setState({
urlIsCopied: true
});
})
.catch(e => console.error(e));
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试安装express-graphql,但出现此错误。请帮忙!
npm install --save express-graphql
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: rest-api@1.0.0
npm ERR! Found: graphql@16.2.0
npm ERR! node_modules/graphql
npm ERR! graphql@"^16.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"^14.7.0 || ^15.3.0" from express-graphql@0.12.0
npm ERR! node_modules/express-graphql
npm ERR! express-graphql@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this …Run Code Online (Sandbox Code Playgroud) 我的目标是获得金额的 5% 并将其发送到公司 PayPal 帐户,其余 95% 将直接发送到其他用户的 Paypal。我怎样才能在 PayPal 代码中做到这一点?
这是我的贝宝代码。
paypal.Button.render({
style: {
size: 'responsive',
color: 'black'
},
env: 'sandbox', // 'sandbox' Or 'production',
client: {
sandbox: 'MyClientID',
production: ''
},
locale: 'en_US',
commit: true, // Show a 'Pay Now' button
payment: function(data, actions) {
// Set up the payment here
return actions.payment.create({
payment: {
transactions: [{
amount: { total: '1.00', currency: 'USD' }
}]
}
});
},
onAuthorize: function(data, actions) {
// Execute the payment here
return actions.payment.execute().then(function(payment) …Run Code Online (Sandbox Code Playgroud)所以我按照磨损钥匙教程来不和谐机器人,我不知道问题是什么,这是错误
/home/container/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Access
at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async GuildApplicationCommandManager.create (/home/container/node_modules/discord.js/src/managers/ApplicationCommandManager.js:117:18) {
method: 'post',
path: '/applications/901999677011005472/guilds/905266476573950023/commands',
code: 50001,
httpStatus: 403,
requestData: {
json: {
name: 'ping',
description: 'Bot uptime/latency checker.',
type: undefined,
options: undefined,
default_permission: undefined
},
files: []
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试查看我的代码,但没有发现任何问题。
这是我的代码,我真的认为代码中有问题。
const DiscordJS = require('discord.js')
const { Intents } = require('discord.js')
const dotenv = require('dotenv')
dotenv.config()
const client = new DiscordJS.Client({
intents: [
Intents.FLAGS.GUILDS, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将彩色框添加为莫里斯图的图例。下图为C3图例。但我无法找到一种方法以同样的方式添加莫里斯。
有人可以帮忙吗?
目前,莫里斯传奇的代码如下:
Morris 的代码 - jQuery
var chart= Morris.Line({
element: 'status-req',
data: <?=json_encode($jsonDataArray)?>,
xkey: 'y',
ykeys: <?=json_encode($deliveryAspect['statusKeys'])?>,
labels: <?=json_encode($deliveryAspect['statusLabels'])?>,
hideHover: 'auto',
resize: true,
smooth:true
});
chart.options.labels.forEach(function(label, i) {
var legendItem = $('<span align="center"></span> ').text(label).css('color', chart.options.lineColors[i])
$('#legend').append(legendItem);
});
Run Code Online (Sandbox Code Playgroud) 我需要在数据名称后显示图表的值,例如([数据颜色] 汽车 50,[数据颜色] 摩托车 200)。我尝试过更改图例标题的值,但它根本不起作用
这是我的代码:
var ctx = document.getElementById('top-five').getContext('2d');
var myChartpie = new Chart(ctx, {
type: 'pie',
data: {
labels: {!! $top->pluck('name') !!},
datasets: [{
label: 'Statistics',
data: {!! $top->pluck('m_count') !!},
backgroundColor: {!! $top->pluck('colour') !!},
borderColor: {!! $top->pluck('colour') !!},
}]
},
options: {
plugins: {
legend: {
display: true,
title: {
text: function(context) {//I've tried to override this but doesn't work
var value = context.dataset.data[context.dataIndex];
var label = context.label[context.dataIndex];
return label + ' ' + value;
},
}
}, …Run Code Online (Sandbox Code Playgroud) 我在向 JS 添加事件侦听器时遇到问题...如果我使用 onclick 属性连接按钮,它可以工作,但如果我在 HTML 中删除它并尝试添加 eventListener('click', myFunction),它就不起作用。顺便说一句,它是一个简单的下拉按钮。
在按钮的以下示例中,我删除了 onclick="myFunction" 并添加了此 - >
JavaScript:
document.getElementById("btn").addEventListener('click', myFunction);
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<button id="btn" class="dropbtn">RECEPT</button>
<div id="myDropdown" class="dropdown-content">
<ul>
<li>-5 jaja</li>
<li>-0.2l mleka</li>
<li>-100g slanine</li>
<li>-200g brasna</li>
<li>-10g putera</li>
<li>-50g sira</li>
<p class="recipeInfo">Kuvati na laganoj …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的不和谐机器人中添加等级卡,为此我尝试使用画布,但是当我使用画布时,一切正常,直到我点击该.drawImage方法。它给我一个错误,说“类型错误:预期图像或画布”。尽管我已经在canvas全局范围内进行了要求,并且与画布有关的所有其他内容也都可以正常工作。
我试过require('canvas')在函数内部,但这也不能解决问题。
const canvas = Canvas.createCanvas(934, 282);
const ctx = canvas.getContext('2d');
const background = Canvas.loadImage('./images/Rank_Card.jpg');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
const attachment = new Discord.Attachment(canvas.toBuffer(), 'welcome-image.png');
msg.channel.send(`Testing...`, attachment);
Run Code Online (Sandbox Code Playgroud)
当它发送消息时,它应该附上图像,但现在它只是给我以下错误。
错误:
C:\Users\Desktop\Discord\iBot\ibot.js:25
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
^
TypeError: Image or Canvas expected
Run Code Online (Sandbox Code Playgroud)