我需要发出几个API请求,然后对组合结果集进行一些处理.在下面的示例中,您可以通过复制相同的请求代码来查看3个请求(到/创建),但我希望能够指定要生成的请求数.例如,我可能希望运行相同的API调用50次.
如何在不重复API调用函数的情况下进行n次调用?
async.parallel([
function(callback){
request.post('http://localhost:3000/create')
.send(conf)
.end(function (err, res) {
if (err) {
callback(err, null);
}
callback(null, res.body.id);
});
},
function(callback){
request.post('http://localhost:3000/create')
.send(conf)
.end(function (err, res) {
if (err) {
callback(err, null);
}
callback(null, res.body.id);
});
},
function(callback){
request.post('http://localhost:3000/api/store/create')
.send(conf)
.end(function (err, res) {
if (err) {
callback(err, null);
}
callback(null, res.body.id);
});
}
],
function(err, results){
if (err) {
console.log(err);
}
// do stuff with results
});
Run Code Online (Sandbox Code Playgroud) 我有以下HTML并想使用Bootstrap的按钮插件 - http://twitter.github.com/bootstrap/javascript.html#buttons来选择"value"元素:
<div class="btn-group pull-right nav-tabs" data-toggle="buttons-radio">
<button class="btn" value="60">Hour</button>
<button class="btn" value="1440">Day</button>
<button class="btn" value="10080">Week</button>
<button class="btn" value="43200">30 Day</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我有以下JavaScript成功执行onClick,但返回undefined.
$('.nav-tabs').button().click( function(e){
var selected = $(this).attr('value');
console.log(selected);
});
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我如何从HTML获取"价值"元素?
我是 ES 新手,需要存储实时数据流。这是基于时间戳的数据。
鉴于结果集将不断更新,任何人都可以就支持分页的最佳方式提出建议吗?
我知道 Twitter 和 Facebook 等使用基于光标的分页。我想知道 ES 中是否有类似的概念?
我试图使用Mongoose运行Geo Box查询,但是没有得到任何结果.我已经构建了一个简化的测试用例:
var mongoose = require('mongoose');
// Schema definition
var locationSchema = mongoose.Schema({
userid: { type : [Number], required: true},
loc: {
'type': {
type: String,
required: true,
enum: ['Point', 'LineString', 'Polygon'],
default: 'Point'
},
coordinates: []
},
tags: { type : [String], index: true, required: true },
create_date : {type: Date, "default": Date.now()}
});
locationSchema.index({ 'loc.coordinates': '2dsphere' });
var Location = mongoose.model('Location', locationSchema);
mongoose.connect('mongodb://localhost/test');
var chkin = new Location({
userid: 1,
loc: { type: 'Point', coordinates: [-122.424088, 37.529876] }, …Run Code Online (Sandbox Code Playgroud) 我希望使用JQuery.param()编码一个对象数组,然后通过ajax GET请求发送数据.
该对象是object类型,当执行console.log(JSON.stringify(obj))时,我得到:
[{"k":48.88975598812273,"B":2.362097778320276},{"k":48.88975598812273,"B":2.217902221679651},{"k":48.85023620829814,"B":2.217902221679651},{"k":48.85023620829814,"B":2.362097778320276},{"k":48.88975598812273,"B":2.362097778320276}]
Run Code Online (Sandbox Code Playgroud)
使用JQuery.param(obj)时,它返回每个值为undefined:
undefined=&undefined=&undefined=&undefined=&undefined=
Run Code Online (Sandbox Code Playgroud)
我已经阅读了类似的帖子,其中一组对象被错误地形成,但是无法看到它是如何格式错误的.
任何人都可以建议吗?
看来我可以在Codeigniter的表单验证中使用PHP的strip_tags函数,如下所示:
$this->form_validation->set_rules('description', 'Description',
'trim|xss_clean|strip_tags');
Run Code Online (Sandbox Code Playgroud)
用strip_tags支持的allowable_tags参数列出标签从过滤例如保持排除<h1>,<strong>等等.
如何在表单验证语法中使用它?
我目前没有使用Backbone.js的经验,在我开始好好看之前,我想知道是否有人可以建议它是否适合我的用例.
我有一个仪表板,我将提供多个实时图表,数据源提供socket.io.
我想在仪表板的多个页面上使用相同的数据源.
主干的模型是否适合这里,即设置一个使用socket.io数据源的模型,然后使其可用于所有视图?
基本上每当调用socket.on时,我都需要在每个视图中更新一个对象.
这可能吗?
任何想法将不胜感激.
此致,本.
我有一个简单的Node.js Rest服务器,它使用Restify提供单个POST服务.我正在尝试编写一个简单的Mocha测试,但它会因超时而失败,尽管成功使用了REST控制台测试(浏览器插件).
我的服务器代码:
/**
* Module dependencies
*/
var restify = require('restify');
var events = require('events');
var util = require('util');
/**
* Create App
*/
var server = restify.createServer({
name: 'test',
version: '0.0.1'
});
var eventsEmitter = new events.EventEmitter();
/**
* Configuraion
*/
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
/**
* Routes
*/
server.post('/post', function (req, res, next) {
var text = "";
req.setEncoding("utf8");
req.on("data", function (chunk) {
text += chunk;
});
req.on("end", function () {
res.send(200, {ok: 'ok'});
});
return next();
}); …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用Mocha,测试一个非常基本的Express 4.0 rest API.
describe('API CALL UNIT TESTING', function(){
var app = require('../../app');
before(function(){
app.listen(3000);
});
describe('GET', function(){
it('respond with json', function(done){
request(app)
.get('/api/compile')
.set('Accept', 'application/json')
.expect('Content-Type', 'application/json')
.expect(200, done)
.end(function(e, res){
//console.log(res)
done();
})
})
});
after(function() {
app.close();
});
});
Run Code Online (Sandbox Code Playgroud)
我在运行测试时遇到以下错误:
1次传球(48ms)1失败
1)API CALL UNIT TESTING"毕竟"挂钩:TypeError:对象函数(req,res,next){app.handle(req,res,next); 没有方法'关闭'
任何人都可以建议导致"毕竟"钩子错误的原因是什么?
我有一个名为“users”的 MySQL 表,其中包含“firstname”和“surname”列。表中有大约一千行。
我现在添加了另一个名为“搜索”的列,我想用名字和姓氏的值填充它,用空格分隔。例如,如果名字 = Bob 和姓氏 = 史密斯,我想用“鲍勃史密斯”填充“搜索”。
任何人都可以就选择这些值并将它们插入新列的更新语句提出建议吗?
最好的问候,本。
我正在寻找使用索引的时间戳创建一个简单的数组,以便我可以通过时间戳访问值而无需遍历数组,但我正在努力!
我需要能够为每一行设置2个值.
例如:
var myarray = [];
var test1 = 'hello'
var test2 = 'world'
myarray[timestamp] = [test1, test2];
Run Code Online (Sandbox Code Playgroud)
因此,对于给定的时间戳,例如12345678,我如何访问test2的值?
感谢任何想法和建议.
问候,本.
node.js ×4
javascript ×3
jquery ×2
mocha.js ×2
arrays ×1
asynchronous ×1
backbone.js ×1
codeigniter ×1
express ×1
function ×1
geospatial ×1
http-post ×1
indexing ×1
json ×1
mongodb ×1
mongoose ×1
mysql ×1
object ×1
pagination ×1
param ×1
restify ×1
socket.io ×1
strip-tags ×1
validation ×1