我正在尝试将socket.io和express.js挂钩在一起:
var socket = require('./socket_chat/socket.js');
var express = require('express'),
app = module.exports.app = express();
var io = require('socket.io').listen(app);
app.use(express.static(__dirname + '/app'));
io.sockets.on('connection', socket);
Run Code Online (Sandbox Code Playgroud)
在线:var io = require('socket.io').listen(app);我收到一个错误:
Error: You are trying to attach socket.io to an expressrequest handler function. Please pass a http.Server instance.
Run Code Online (Sandbox Code Playgroud)
有关此错误的SO/google似乎没有任何内容......
我正在尝试将大块文本分成多个字符串,每个字符串为148个字符,同时避免切断单词.
我现在有这个,这是分裂的话:
var length = shortData.new.length;
if (length < 160){
outputString[0] = shortData.new;
document.write(outputString[0]);
}
if (length > 160 && length < 308){
outputString[0] = shortData.new.substring(0,148);
outputString[1] = shortData.new.substring(148,length);
document.write(outputString[0]+"(txt4more..)");
document.write(outputString[1]);
}
if (length > 308 && length < 468){
outputString[0] = shortData.new.substring(0,148);
outputString[1] = shortData.new.substring(148,308);
outputString[2] = shortData.new.substring(308,length);
document.write(outputString[0]+"(txt4more..)");
document.write(outputString[1]+"(txt4more..)");
document.write(outputString[2]);
}
if (length > 468 && length < 641){
outputString[0] = shortData.new.substring(0,148);
outputString[1] = shortData.new.substring(148,308);
outputString[2] = shortData.new.substring(308,468);
outputString[3] = shortData.new.substring(468,length);
document.write(outputString[0]+"(txt4more..)");
document.write(outputString[1]+"(txt4more..)");
document.write(outputString[2]+"(txt4more..)");
document.write(outputString[3]);
}
Run Code Online (Sandbox Code Playgroud) 我记得在某些时候使用方程来做到这一点 - 你如何在Javascript中做到这一点?
插件两个数字范围:
rangeX = 1 (through) 10;
rangeY = 300.77 (through) 559.22;
Run Code Online (Sandbox Code Playgroud)
输入范围Y比例中的值:
inputY = 328.17;
Run Code Online (Sandbox Code Playgroud)
转换为rangeX比例的比例值:
outputX = 1.43;
Run Code Online (Sandbox Code Playgroud) 这似乎是一个简单的问题,但是如何创建一个具有一系列单选按钮选项的基本HTML表单,最后一个是填充自定义响应的文本字段(即"其他").
我现在拥有的:
Reason given for stop? <br>
<input type="radio" name="reason" value="Fit Description">Fit Description<br>
<input type="radio" name="reason" value="Suspicious Behavior">Suspicious Behavior<br>
<input type="radio" name="reason" value="No Reason Given">No Reason Given<br>
<input type="radio" name="reason" value="">Other<br>
Run Code Online (Sandbox Code Playgroud) 尝试在Node.js和MongoDB中查找唯一ID,方法是创建一个while循环,在MongoDB中查询现有ID,直到找到唯一值.如果ID已在使用中,则数字会在末尾递增,直到Mongo不返回任何内容.
一切正常,除了break;找到唯一ID 的声明.Node.js返回:SyntaxError: Illegal break statement
代码:
db.collection('landmarks').findOne({'id':uniqueIDer}, function(err, data){
//if ID exists already
if (data.id){
var uniqueNumber = 1;
while (1) {
var uniqueNum_string = uniqueNumber.toString();
var newUnique = data.id + uniqueNum_string;
db.collection('landmarks').findOne({'id':newUnique}, function(err, data){
if (data.id){
uniqueNumber++;
}
else {
saveLandmark(newUnique);
break;
}
});
}
}
else {
saveLandmark(uniqueIDer);
}
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
编辑:
这是使用异步的固定代码,如果有人需要它:)
db.collection('landmarks').findOne({'id':uniqueIDer}, function(err, data){
if (data){
var uniqueNumber = 1;
var newUnique;
async.forever(function (next) {
var uniqueNum_string = uniqueNumber.toString();
newUnique = data.id …Run Code Online (Sandbox Code Playgroud) 我试图在C++中获取一个字符串并查找其中包含的所有IP地址,并将它们放入一个新的矢量字符串中.
我已经阅读了很多关于正则表达式的文档,但我似乎无法理解如何做这个简单的函数.
我相信我可以使用这个Perl表达式来查找任何IP地址:
re("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b");
Run Code Online (Sandbox Code Playgroud)
但我仍然难以理解如何做其余的事情.
使用Cordova Ionic Android,您可以使用以下命令调用搜索键盘<input type="search">:
我正试图通过以下方式访问表情符号键盘: <input type="textShortMessage">
但它没有用.
textShortMessage是基于这个问题:Android键盘与表情符号,用于直接Android开发.
我需要确保添加到队列中的同一作业在一段时间内不会重复。
\n\n是否值得D/M/Y-HH:M在我的独特中包含部分时间戳(即)jobId,以便仅在不在同一分钟内时才进行处理?
如果在 处添加一项作业,在 处添加12:01另一项作业,它仍然会重复12:09\xe2\x80\x93,它仍然会重复,或者 Bull 是否有更好的方法来做到这一点?
我通过Angular.js使用jQuery File Uploader.我需要将服务器的响应从图像上传传递到Angular $ scope,但是我无法访问done函数中的$ scope :
function LandmarkNewCtrl($location, $scope, db) {
$('#fileupload').fileupload({
url: '/api/upload',
dataType: 'text',
done: function (e, data) {
$scope.landmark.avatar = data.result;
}
});
}
Run Code Online (Sandbox Code Playgroud)
获取"未捕获的TypeError:无法读取未定义的"属性'标志'错误.
如何将$ scope传递给done: function()?
我正在导出一个函数列表./list:
export default {
f1: a,
f2: b,
f3: c
}
Run Code Online (Sandbox Code Playgroud)
其中a,b,c是单独的函数,并尝试将其中一个函数导入另一个文件:
import { f1 } from './list';
Run Code Online (Sandbox Code Playgroud)
但是,f1()是undefined在新的文件.如果我导入为:
import list from './list';
Run Code Online (Sandbox Code Playgroud)
并称之为list.f1()IS定义.
如何{ f1 }按定义导入?
javascript ×5
node.js ×3
regex ×2
android ×1
angularjs ×1
asynchronous ×1
boost ×1
boost-regex ×1
bull.js ×1
c++ ×1
cordova ×1
ecmascript-6 ×1
es6-modules ×1
express ×1
forms ×1
html ×1
ionic ×1
job-queue ×1
jquery ×1
keyboard ×1
mongodb ×1
sms ×1
socket.io ×1
while-loop ×1