我在firestore查询中尝试实现逻辑OR运算符.
db.collection('users').where('company_id', '==', companyId)
.where('role', '==', 'Maker')
.where('role', '==', 'Checker')
.where('role', '==', 'Approver')
.get().then(function(adminsSnapshot){
//Some processing on dataSnapshot
})
Run Code Online (Sandbox Code Playgroud)
但这不是实施OR的正确方法.
我希望所有用户都拥有"Maker,Checker或Approver"角色.
我如何在firestore查询中实现OR?Doc中没有任何内容.
在尝试读取Reactjs中的excel文件时,我正在尝试并试探我的脑袋.
我已经尝试了多个库,如Sheetjs,excel-parser,exceljs等(如8-9)库.
我在每个库中都会遇到奇怪和不同的错误.
例如,我使用excel-parser并获得以下错误
Module not found: 'child_process'
Run Code Online (Sandbox Code Playgroud)
那是因为它是一个节点模块,不能在浏览器中工作.
有人知道一些好的和简单的库可以在浏览器中使用reactjs吗?
由于Cloud Firestore是新的,我在使用它时遇到了问题.
我必须得到所有用户的集合并遍历它.但它没有用.
db.collection("users").get().then(function(querySnapshot){
console.log(querySnapshot.data());
});
Run Code Online (Sandbox Code Playgroud)
它说:
querySnapshot.data不是一个函数
以下代码:
callFireBase(mobileToCheck){
db.collection("users").where("mobile_no", '==', mobileToCheck).get().then(function(querySnapshot){
if (querySnapshot.exists) {
var userData = querySnapshot.data();
var userId = querySnapshot.id;
console.log(mobileToCheck + "Exist In DB");
}else{
console.log(mobileToCheck + "Do Not Exist In DB");
}
});
}
Run Code Online (Sandbox Code Playgroud)
总是打印
923052273575在DB中不存在
即使存在,请参阅以下图像以供参考.
我想在我的reactjs应用程序中使用firestore.
当我从firebase配置对象调用firestore时.
它说
firebase2.default.firestore不是一个函数
这是代码
import firebase from 'firebase'
const config = {
apiKey: "AIzaSxxxxxxqpUeqKXI",
authDomain: "payxxxxxa1.firebaseapp.com",
databaseURL: "https://payxxxxxxxa1.firebaseio.com",
projectId: "payxxxxxxja1",
storageBucket: "payxxxxxa1.appspot.com",
messagingSenderId: "281xxxxxxxx576"
}
firebase.initializeApp(config)
export const fire = firebase
export const ref = firebase.database().ref()
export const firebaseAuth = firebase.auth
export const messaging = firebase.messaging();
export const db = firebase.firestore();
Run Code Online (Sandbox Code Playgroud)
Firebase版本是4.5.0
npm list firebase> firebase@4.5.0
我做错了吗?
当我在浏览器中运行CI项目时,使用localhost/hr,它将我重定向到localhost/dashboard /.
搜索了不同的解决方案,但没有得到它的工作.这是我在" htdocs/hr "文件夹中的.htaccess文件
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
注意:htdocs文件夹中没有.htaccess文件.
当我删除/重命名index.php文件并访问htdocs时,它给了我错误.
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Run Code Online (Sandbox Code Playgroud)
我做错了什么,如何让它运作?
我的htdocs/hr文件夹的屏幕截图是下面的
由于firestore还不是很老,所以在某些情况下有很小的帮助.
我试图从Firestore获得第二个记录,但它正在获得第一个.我知道这是错误的查询:
db.collection("batches")
.where('added_at', "<", paymentData.added_at) //Here paymentData is last record
.limit(1).get().then(function(prevSnapshot){
})
Run Code Online (Sandbox Code Playgroud)
例如,我有3条记录
A. added_at: 1 Jan, 2017
B. added_at: 2 Jan, 2017
C. added_at: 3 Jan, 2017
Run Code Online (Sandbox Code Playgroud)
我现在C在paymentData中,我想要记录B.但它正在获得记录A.
我如何获得第二个最后记录?
编辑:
每条记录的时间戳总是比前一个更新(即使它可以是1分钟.例如,前一个27 Jan, 2017 5:20 PM和新的27 Jan, 2017 5:21 PM)
而paymentData将始终拥有最新记录.
基本上我想比较当前付款和先前付款的两个值,并显示它与用户的差异.
我正在尝试在我的reactjs应用程序中向用户发送推送通知。我已添加Firebase,请求用户具有通知权限。很好
但是现在我想注册设备令牌。但这给了我错误:
消息传递:我们无法注册默认服务工作者。无法注册ServiceWorker:脚本具有不受支持的MIME类型('text / html')。(消息/服务工作者注册失败)
在哪里添加firebase-messaging-sw.js文件?如何在React App中注册服务工作者?
这是我用来注册设备令牌的代码:
messaging.getToken()
.then(function(currentToken) {
if (currentToken) {
// sendTokenToServer(currentToken);
// updateUIForPushEnabled(currentToken);
} else {
// Show permission request.
console.log('No Instance ID token available. Request permission to generate one.');
// Show permission UI.
// updateUIForPushPermissionRequired();
// setTokenSentToServer(false);
}
})
.catch(function(err) {
console.log('An error occurred while retrieving token. ', err);
//showToken('Error retrieving Instance ID token. ', err);
//setTokenSentToServer(false);
});
Run Code Online (Sandbox Code Playgroud)
注意:它不是本机响应,而是Web应用程序。
由于firestore是新的,我在使用它时遇到了问题.
我必须得到所有用户的集合并遍历它.但它没有用.
db.collection("users").get().then(function(querySnapshot){
console.log(querySnapshot.data());
});
Run Code Online (Sandbox Code Playgroud)
它说:
querySnapshot.data不是一个函数
以下代码:
callFireBase(mobileToCheck){
db.collection("users").where("mobile_no", '==', mobileToCheck).get().then(function(querySnapshot){
if (querySnapshot.exists) {
var userData = querySnapshot.data();
var userId = querySnapshot.id;
console.log(mobileToCheck + "Exist In DB");
}else{
console.log(mobileToCheck + "Do Not Exist In DB");
}
});
}
Run Code Online (Sandbox Code Playgroud)
总是打印
923052273575在DB中不存在
即使存在,请参阅以下图像以供参考.在文档中,他们告诉我(我已经使用过)这种方式.
安装所有node_modules时遇到此问题。这让我发疯。
babel-loader@7.1.2需要webpack @ 2的同位体|| 3,但未安装。
这是我的package.json文件
{
"name": "react-router-firebase-auth",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react-scripts": "0.9.5"
},
"dependencies": {
"@atlaskit/button": "3.0.0",
"@atlaskit/css-reset": "1.1.4",
"@atlaskit/field-text": "4.0.1",
"@atlaskit/modal-dialog": "2.1.1",
"@atlaskit/page": "4.0.1",
"@atlaskit/util-shared-styles": "2.3.1",
"@shopify/polaris": "^1.5.1",
"babel-eslint": "^7.0.0",
"bootstrap": "^3.3.7",
"eslint": "3.16.1",
"eslint-plugin-react": "6.4.1",
"express": "^4.16.1",
"firebase": "^4.5.0",
"firebase-admin": "^5.4.1",
"firestore": "^1.1.6",
"fixed-data-table": "^0.6.4",
"griddle-react": "^1.8.1",
"jquery": "^3.2.1",
"node-localstorage": "^1.3.0",
"nodemon": "^1.12.1",
"react": "^15.5.3",
"react-bootstrap": "^0.31.3",
"react-bootstrap-button-loader": "^1.0.8",
"react-bootstrap-navbar": "^1.1.0",
"react-data-grid": "^2.0.59", …Run Code Online (Sandbox Code Playgroud) 我有一个电话号码,我想像审查表格一样显示它.例如,我有:+923451234567
我想显示它像: +923*******67
将使用Str.replace函数,但如何:
var str = '+923451234567'
str.replace(i_Dont_Know_What, '*');
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下字符串包含13个字符.我想用"*"替换第5-11个字符
我在某个地方找到了这个,但这不是我想要的.
var str = "name(replace these parenthesis by @)domain.com";
var patt1 = /\(.*@\)/i;
document.write(str.replace(patt1,"@"));
Run Code Online (Sandbox Code Playgroud)
我怎么做到这一点?
如何在firebase管理SDK中获取currentUser.在客户端SDK中我们可以使用
onAuthStateChanged() or firebase.auth().currentUser()
Run Code Online (Sandbox Code Playgroud)
在NodeJs Server.js文件中,firebase 管理员SDK onAuthStateChanged()不起作用,这里有什么用?
基本上我只想登录用户访问我的innerPages所以我使用express,nodejs app.get方法来创建路由.
app.get('/', authenticationRequired ,function(req,res){
res.sendFile(path.join(__dirname+'/index.html'));
});
Run Code Online (Sandbox Code Playgroud)
并尝试编写authenticationRequired方法(根据用户是否登录,返回false或true).
我试图通过邮件发送数据或获取firebase云功能,但无法使其工作.
这是我的ajax:
$.ajax({
url: 'https://us-ceXXX1-reXXXts-fXXa-pr.cloudfunctions.net/helloWorld',
dataType: "json",
method: 'GET',
crossDomain: true,
body: {
mobileNo: "WzkyMzXXXXXXXXXXXc5ODBd"
},
success: function(data){
console.log('succes: '+data);
}
});
Run Code Online (Sandbox Code Playgroud)
这是云功能:
exports.helloWorld = functions.https.onRequest((request, response) => {
var responsez = response;
console.log("DATA IS:"+request.data); //prints undefined
console.log("BODY IS:"+JSON.stringify(request.body)); //prints BODY ID: {}
var mobNo = request.body.mobileNo;
var options = {
body: {mobileNo: mobNo, applicationVersion: "1.0"},
url: 'http://nxxxpi.fixxxa.wxb.pk/GetxxxxxxoUxr',
headers: {
'appKey':'jDxxxxxxxOr',
'appId':'2xxxxx9'
},
json: true
}
cors(request, response, () => {requestz.post(options, function (error, response, body) { …Run Code Online (Sandbox Code Playgroud) 我有一个阵列
var arr = ['0333', '0444', '0334'];
Run Code Online (Sandbox Code Playgroud)
我有一系列的对象.
var objArray = [{'name':'abc', 'phone':'0333'},
{'name':'xyz', 'phone':'0334'},
{'name':'fgfh', 'phone':'0999'},
{'name':'abc', 'phone':'0666'},
{'name':'abc', 'phone':'0444'}
]
Run Code Online (Sandbox Code Playgroud)
现在我想搜索所有arr值/索引objArray并分离具有匹配值的对象,并且没有匹配的值
var matchingArray = [];
var noMatchingArray = [];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < objArray.length; j++) {
if(objArray[j]['phone'] == arr[i]){
matchingArray.push(objArray);
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何添加没有匹配的对象noMatchingArray?