我正在尝试使用云功能将 FCM 发送到我的 React 应用程序。云函数正在执行,但客户端未收到通知。
这里是云函数代码。
exports.sendPush = functions.database.ref('/settings2').onWrite(event => {
let projectStateChanged = false;
let projectCreated = false;
let projectData = event.data.val();
if (!event.data.previous.exists()) {
projectCreated = true;
}
if (!projectCreated && event.data.changed()) {
projectStateChanged = true;
}
let msg = 'A project state was changed';
if (projectCreated) {
msg = `The following new project was added to the project: ${projectData.title}`;
}
tokens.push("fIGxxxxGtDGxxxx DEVICE Token");
let payload = {
notification: {
title: 'Firebase Notification',
body: 'This Is Message',
sound: …
Run Code Online (Sandbox Code Playgroud) javascript firebase reactjs google-cloud-functions firebase-cloud-messaging
我有一个 div,我想将this
div传递给 onlick 函数并更改它的类(或添加类)。
<div className="history-node" onClick={() => this.handleHistoryClick(this)}>
<span className="history-title">Uploaded</span>
<span className="history-date">October 9, 2017</span>
</div>
Run Code Online (Sandbox Code Playgroud)
功能是:
handleHistoryClick(el){
console.log("History Clicked");
console.log(el);
}
Run Code Online (Sandbox Code Playgroud)
但这是打印当前的 React 组件类,它是
Paymentdetail
.
我想要的是:
handleHistoryClick(el){
$(el).addClass('active');
}
Run Code Online (Sandbox Code Playgroud)
编辑: 我有多个history-node
元素。因此,添加状态以更改类将不适用于多个元素。
我如何实现这一目标?
我一直在搜索并尝试了多种解决方案,但可以得到任何帮助结果,我想清除/删除所有匹配模式的键products:*
。
以下是我尝试过的事情。
Redis::del('products:*');
Redis::del('*products:*');
Redis::del('*products*');
Run Code Online (Sandbox Code Playgroud)
但没有任何效果。
如果我提供确切的密钥名称,则它正在删除密钥: Redis::del('products:2:3:45');
密钥是这样生成的:products:1:4:45
我已阅读文档,但可以找到有关我的查询的任何信息。
请帮忙。
我在我的 React 本机应用程序中添加了一个 Lottie 加载动画,该动画到目前为止正在运行,但不知何故颜色没有显示,而仅显示白色动画。
这是代码。
<View style={styles.lottieLoadingWrapper}>
<LottieView
style={styles.lottieLoading}
source={require('../assets/loading-2.json')}
autoPlay
loop
/>
</View>
Run Code Online (Sandbox Code Playgroud)
我没有在样式表中做任何事情。我尝试过多种动画,但都是简单的白色。我在这里犯的错误可能是什么?
更新:以下是样式代码
lottieLoadingWrapper: {
width: 50,
height: 50,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'yellow',
alignSelf: 'center',
},
lottieLoading:{
width: 50,
height: 50,
backgroundColor: 'rgba(120, 120, 120, 0.66)',
justifyContent: 'center',
alignItems: 'center',
}
Run Code Online (Sandbox Code Playgroud)
以下是我正在使用的动画
如何迭代嵌套的 firebase 对象。
Publications-
|
|-Folder1------
| |-hdgjg76675e6r-
| | |-Name
| | |-Author
| |
| |+-hdgjdsf3275e6k
| |+-hd345454575e6f
|+-Folder2
Run Code Online (Sandbox Code Playgroud)
在出版物中,我有文件夹,在文件夹中我有对象(包含名称、作者等属性)
到目前为止我已经遍历了文件夹。
snapshot.forEach(function (snapshot) {
var key = snapshot.key();
var obj = snapshot.val();
console.log(key);
//output => Folder1 , Folder2 etc
});
Run Code Online (Sandbox Code Playgroud)
当我打印obj时
console.log(obj);
Run Code Online (Sandbox Code Playgroud)
它显示
如何迭代obj变量,因为它包含hdgjg76675e6r
等hdgjdsf3275e6k
以及进一步的内容?
我正在尝试为 React修改Shopify Polaris Button组件的颜色,我尝试更改 style.css 文件但没有任何反应。
知道怎么做吗?
应用程序.js
import React, { Component } from 'react';
import '@shopify/polaris/styles.css';
import {Page, Card, Button} from '@shopify/polaris';
class App extends Component {
render() {
return (
<div className="App">
<Page title="Example app">
<Card sectioned>
<Button onClick={() => alert('Button clicked!')}>Example button</Button>
</Card>
</Page>
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
我正在尝试修改node_modules/@shopify/polaris/styles.css
,但它对按钮颜色没有任何影响。
到处搜索但找不到任何解决方案或答案。我可以使用以下代码获取时间戳:
var timestamp = firebase.database.ServerValue.TIMESTAMP;
Run Code Online (Sandbox Code Playgroud)
但我想存储负时间戳以进行排序。我怎样才能得到它?
当我尝试将它与-1相乘时,它会给出 NaN 错误,因为它是一个对象。如何?
我正在查询 firestore 以获得一些结果。但是在对文档运行 forEach 循环之前,我想知道集合快照中是否有任何文档,并且即使其中有文档也snapshot.exist()
总是给出false。
db.collection("users").where("mobile_no", '==', mobileToCheck).get().then(function(querySnapshot){
if (querySnapshot.exists) { \\THIS ALWAYS RETURNING FALSE
querySnapshot.forEach(doc => {
console.log(doc.data());
});
console.log(mobileToCheck + "Exist In DB");
}else{
console.log(mobileToCheck + "Do Not Exist In DB");
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么知道有没有结果?
我在设置react-chartjs时遇到此错误,我正在使用此处给出的示例。这是我得到的错误:
Uncaught (in promise) TypeError: Cannot read property 'xLabels' of undefined
at updatePoints (core.js:127)
at Object.classData.componentWillReceiveProps (core.js:48)
...... so on
Run Code Online (Sandbox Code Playgroud)
在这篇文章中,他们说他们已经修复了它,但我认为他们没有。
这是我的代码:
var Chart = require('chart.js');
var LineChart = require("react-chartjs").Line;
export default class Dashboard extends Component {
constructor(props){
super(props);
var result = '';
this.state = {
chartData: '',
chartOptions: ''
};
}
componentDidMount(){
var chartData = {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据保存到 QuestionOption 表中并面临检测到的递归问题。我一直在到处搜索,但可以找到这个问题的任何答案。以下是我试图将数据保存到数据库的地方。
$question = new Question();
$question->type = $request->type;
$question->optional = $request->optional;
$question->question = $request->question;
$question->status = $request->status;
$question->save(); ////// WORKS PERFECTLY TILL THIS LINE
if ($request->type == 'choice') {
foreach ($request->options as $key => $option) {
$option = new QuestionOption(); ////////HERE I AM FACING THAT ERROR
$option->question_id = $question->id;
$option->option = $option;
$option->status = 'active';
$option->save();
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我用于 QuestionOption 的模型,我找不到任何问题。
class QuestionOption extends Model
{
protected $dates = [
'created_at',
'updated_at',
];
protected $fillable = [
'question_id', …
Run Code Online (Sandbox Code Playgroud) 我在 React 组件中有数据数组(JS)。我想使用该数组上的循环生成动态 div。
一是可以用 jquery / javascript 来完成
componentDidMount(){
var headingsArray = //contains some data from backend;
for (var i = 0; i < headingsArray.length; i++) {
var maprow = '';
maprow += "<div>"+ headingsArray[i] +"</div>";
//Some More Data In maprow
$('.parentDiv').append(maprow);
}
}
render(){
return(
<div className="parentDiv"></div>
)
}
Run Code Online (Sandbox Code Playgroud)
反应方式是什么?因为我是新来的反应
我正在尝试使用 SheetJs 读取 Excel 文件
但得到以下错误。
未捕获的类型错误:无法读取未定义的属性“0”
这是我的文件处理函数
function handleFileSelect(evt) {
//Get the files from Upload control
var files = evt.target.files;
var i, f;
//Loop through files
for (i = 0, f = files[i]; i != files.length; ++i) {
var reader = new FileReader();
var name = f.name;
reader.onload = function (evt) {
var data = evt.target.result;
var result;
/* convert from workbook to array of arrays */
var first_worksheet = data.Sheets[data.SheetNames[0]];
var data = XLSX.utils.sheet_to_json(first_worksheet, {header:1});
alert(result[0].Column1);
};
reader.readAsArrayBuffer(f); …
Run Code Online (Sandbox Code Playgroud) javascript ×9
reactjs ×5
firebase ×4
jquery ×4
laravel ×2
php ×2
caching ×1
chart.js ×1
css ×1
laravel-5.7 ×1
lottie ×1
polaris ×1
react-native ×1
redis ×1
shopify ×1