我是这个node.js的新手..我对这个回调有点困惑..在我的应用程序内部for循环我调用异步函数调用,我想我的问题是在我得到异步调用的响应之前我的for loop get loop.
我的代码:
async.forEach(Object.keys(config), function(key, next) {
search(config[key].query, function(err, result) { //
console.log("fffffffffff="+ util.inspect(result))-------- >>>Getting undefined..
if (err) return next(err) //
var json = JSON.stringify({
"result": result
});
results[key] = {
"result": result
}
console.log("rrrrrrrr="+util.inspect(results[key]))
next() // <---- critical piece. This is how the forEach knows to continue to the next loop. Must be called inside search's callback so that it doesn't loop prematurely.
})
},
function(err) {
console.log('iterating done');
res.writeHead(200, {
'content-type': 'application/json'
});
res.end(JSON.stringify(results));
});
} …
Run Code Online (Sandbox Code Playgroud) 我正在使用 JEST 框架对我的 node.js 项目进行单元测试。我用于mockImplementationOnce
模拟第三方库方法,如下所示:
jest.mock('abc', () => {
return { a: { b: jest.fn() } };
});
const abcjs= require('abc');
describe("1st test", () => {
test("should return true", async () => {
abcjs.a.b.mockImplementationOnce(() => Promise.resolve(
return true}
));
});
});
describe("2nd test", () => {
test("should return false", async () => {
abcjs.a.b.mockImplementationOnce(() => Promise.resolve(
return false}
));
});
});
Run Code Online (Sandbox Code Playgroud)
第一个测试已成功执行,但第二个测试它调用实际方法,它不是模拟。
我尝试重置模拟afterEach
,但没有帮助。
对于这个时髦的编程我是新手.我编写了一个在我的本地系统(localhost:2100
)中运行的API .
现在我想使用groovy代码向这个API发出一个简单的GET请求.我搜索了很多,但我找不到明确的指导.
我试过这个:
http://www.kellyrob99.com/blog/2013/02/10/groovy-and-http/ http://rest.elkstein.org/2008/02/using-rest-in-groovy.html 等.但没有任何作用.
我也遇到过HttpBuilder
.我无法清楚地了解这一点.请分享您的想法.
编辑:
我试过这个:
def client = new RESTClient("http://localhost:2100");
def res = client.get(path:"xxx/yyy/zzz")
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Groovy:unable to resolve class RESTClient
Run Code Online (Sandbox Code Playgroud)
我是否需要在pom.xml中添加依赖项?
我是loopback的新手,我刚刚开始实施教程 https://docs.strongloop.com/display/public/LB/Connect+your+API+to+a+data+source
但我收到错误:
[error: relation "public.acl" does not exist].
Run Code Online (Sandbox Code Playgroud)
我搜索了很多,但无法找到解决方案.请帮我解决这个问题.谢谢..
提到有很多的教程后,我才知道,而不是Menu
他们ActionBar
的> API 10
.但是我正在使用API 7
sdk进行测试,我曾经用它Menus
来显示文本drawable images
.但只有文本即将到来,并且菜单选项中不显示可绘制的图标图像.请帮我解决这个问题.
我的XML
:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!--
Single menu item
Set id, icon and Title for each menu item
-->
<item
android:id="@+id/savedstory"
android:background="#000000"
android:minHeight="20dp"
android:title="Saved Stories"/>
<item
android:id="@+id/setting"
android:background="#000000"
android:minHeight="20dp"
android:title="Settings"/>
<item
android:id="@+id/Bookmark"
android:background="#000000"
android:minHeight="20dp"
android:title="Bookmark This"/>
<item
android:id="@+id/share"
android:background="#000000"
android:minHeight="20dp"
android:title="Share This"/>
<item
android:id="@+id/save"
android:background="#000000"
android:minHeight="20dp"
android:title="Save This"/>
<item
android:id="@+id/small"
android:icon="@drawable/font3"
android:minHeight="20dp">
This icon is not showing.
/>
<item …
Run Code Online (Sandbox Code Playgroud) 在我的节点应用程序中,我使用"Winston"日志记录在单独的文件中打印错误.
我按照本教程.
当我试图从其他文件访问记录器....
我的代码:
var winston = require('winston');
var fs = require('fs');
fs.mkdir('./logs', function(err) {
if (err) throw err;
});
// Define levels to be like log4j in java
var customLevels = {
levels: {
debug: 0,
info: 1,
warn: 2,
error: 3
},
colors: {
debug: 'blue',
info: 'green',
warn: 'yellow',
error: 'red'
}
};
// create the main logger
var logger = new(winston.Logger)({
level: 'debug',
levels: customLevels.levels,
transports: [
// setup console logging
new(winston.transports.Console)({
level: 'info', …
Run Code Online (Sandbox Code Playgroud) 我使用Loopback框架开发了一个API,因为我必须insert or update
使用一个表.
我的表如下所示:
userid bbid saved id(PK)
1 5 1000 1
Run Code Online (Sandbox Code Playgroud)
所以当下次if(bbid = 5)时它应该更新上面的行,如果没有bbid = 5那么它应该插入上面的表中.
我尝试了以下方法:
app.models.modelname.upsert({
bbid: bb.id,
saved: Saved,
userid: 1
}, function(err, res) {});
Run Code Online (Sandbox Code Playgroud)
编辑COMPOSITE ID:
app.models.modelname.upsert({
bbid: vvvv.bbid,
userid: 1,
saved: amountSaved
}, function(err, res) {});
Run Code Online (Sandbox Code Playgroud)
它也说过了Loopback doc
upsert - checks if the instance (record) exists, based on the designated
ID property, which must have a unique value; if the instance already exists,
the method updates that instance. Otherwise, it inserts a …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 macOS 中运行基本的 react-native 应用程序。我通过 brew 安装了节点。
My node version: v6.12.0
npm version :5.5.1
Run Code Online (Sandbox Code Playgroud)
然后我使用 npm 安装了 reatc-native-cli。现在,当我尝试使用react-native init
它创建一个项目时说react-native command not found
。
我尝试了所有解决方案,但没有希望。因为我是这个 react-native 指南的新手,所以我解决了这个问题。提前致谢。
我尝试了所有帖子,包括
在我的应用程序中,我必须实现一个自动滚动的textview,我引用了这个链接.
现在我有一个滚动的tetxview.But根据我的要求是我有一个字符串数组(我已经解析,我有一些字符串)..考虑数组可能是
string[] array=new string{"fgsdfd","gdfghdjhsd","gdfjhsgfhds"};
Run Code Online (Sandbox Code Playgroud)
现在我希望这个数组显示在该textview中(将自动滚动).
我想这样:
fgsdfd gdfghdjhsd gdfjhsgfhds------------------>this will scroll automatically
Run Code Online (Sandbox Code Playgroud)
这是我的textview(滚动):
<TextView
android:text="Really Long Scrolling Text Goes Here.... ..... ............ .... ...."
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:id="@+id/TextView03"
android:padding="5dip"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
如何将字符串数组设置为tetxview ..请帮助我.
我正在使用 redis 在我的项目中存储会话。
在app.js
var client = redis.createClient();
client.on('error', function (err) {
console.log('could not establish a connection with redis. ' + err);
});
client.on('connect', function (err) {
console.log('connected to redis successfully');
});
Run Code Online (Sandbox Code Playgroud)
在我的routes.js
文件中,我必须从 redis 获取所有信息,因此我使用以下内容:
var client = redis.createClient();
client.on('error', function(err){
console.log('Something went wrong ', err)
});
Run Code Online (Sandbox Code Playgroud)
但每次都是连接到redis。我怎样才能在我的系统中连接一次redisapp.js
并在任何地方使用它。请提出想法。提前致谢。
编辑
app.js
module.exports.client = client;
routes.js
var client = require("../app.js").client;
client.hgetall();
Run Code Online (Sandbox Code Playgroud)
但我正在收到error
TypeError: Cannot read property 'hgetall' of undefined
Run Code Online (Sandbox Code Playgroud) node.js ×7
javascript ×3
android ×2
loopbackjs ×2
groovy ×1
http ×1
jestjs ×1
macos ×1
react-native ×1
redis ×1
textview ×1
unit-testing ×1
upsert ×1
winston ×1