我有2个数组,值将从数据库加载,下面是一个例子:
$arr1 = array(1,2,3);
$arr2 = array(1,2,3,4,5,6,7);
Run Code Online (Sandbox Code Playgroud)
我想要做的是检查是否所有的值中$arr1的存在$arr2.上面的例子应该是一段TRUE时间:
$arr3 = array(1,2,4,5,6,7);
Run Code Online (Sandbox Code Playgroud)
比较$arr1有$arr3将返回FALSE.
通常我使用in_array因为我只需要将单个值检查到数组中.但在这种情况下,in_array不能使用.我想看看是否有一种简单的方法来进行最小循环检查.
更新澄清.
第一个数组将是一个包含唯一值的集合.第二个数组可以包含重复的值.它们在处理之前都保证有阵列.
我有一个USB条码扫描器,它通过USB OTG插入设备.因为它被选为键盘HID设备,所以当输入被聚焦时,软键盘被禁用.
我目前有一个从JavaScript触发键盘的方法.
class JsObject {
@JavascriptInterface
public void InvokeKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(findViewById(R.id.webView), InputMethodManager.SHOW_FORCED);
}
}
webview.addJavascriptInterface(new JsObject(), "Android");
Run Code Online (Sandbox Code Playgroud)
我基本上想要它在webview中的以下动作上打开键盘.
const button = document.querySelector('.fire-keyboard');
button.addEventListener('click', () => Android.InvokeKeyboard());
Run Code Online (Sandbox Code Playgroud)
它可以在从webview手动调用时工作,但我希望能够单击触发它的按钮,然后单击按钮会丢失输入框焦点.
只是添加,我不希望键盘在聚焦输入框时显示,只显示单击按钮时触发它.默认情况下,它显示焦点.
我正在使用"pg"模块来处理postgresql db,如何使用pg调用函数我有疑问,
我用查询方法调用函数,
client.query("SELECT * FROM SQSP_IsUserNameExists($1)",[userName], function(err, result) {
// some code.
});
Run Code Online (Sandbox Code Playgroud)
这工作正常,但这是调用postgresql函数的正确方法.
我有一个这样的课:
import net from 'net';
import {EventEmitter} from 'events';
import Promise from 'bluebird';
class MyClass extends EventEmitter {
constructor(host = 'localhost', port = 10011) {
super(EventEmitter);
this.host = host;
this.port = port;
this.socket = null;
this.connect();
}
connect() {
this.socket = net.connect(this.port, this.host);
this.socket.on('connect', this.handle.bind(this));
}
handle(data) {
this.socket.on('data', data => {
});
}
send(data) {
this.socket.write(data);
}
}
Run Code Online (Sandbox Code Playgroud)
如何将send方法转换为promise,从socket的data事件中返回一个值?除了可以轻松抑制的连接消息之外,服务器仅在向其发送数据时发回数据.
我尝试过类似的东西:
handle(data) {
this.socket.on('data', data => {
return this.socket.resolve(data);
});
this.socket.on('error', this.socket.reject.bind(this));
}
send(data) {
return …Run Code Online (Sandbox Code Playgroud) 我试图将角度过渡应用于元素,但它不起作用.我也添加了web-animation-js但仍然没有效果.在onMouseleave和onMouseover函数上添加了实现
// package.json
"web-animations-js": "^2.3.1",
Run Code Online (Sandbox Code Playgroud)
//项目清单
<li class="list-group-item" (mouseover)="onMouseover()" (mouseleave)="onMouseleave()" [@usrSt]="st" [routerLink]= "['/users', i+1, person.name]" *ngFor="let person of (personsList | filter:coursestat:'chosenCourse'); let i = index">
Run Code Online (Sandbox Code Playgroud)
//列表组件
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.css'],
animations: [
trigger('usrSt', [
state('active', style({ 'background-color': '#cfd8dc' })),
state('inactive', style({ 'bacckground-color': '#fff' })),
transition('active => inactive', animate('1400ms ease-in')),
transition('inactive => active', animate('400ms ease-out'))
])
]
})
export class ListComponent implements OnInit, OnDestroy {
public personsList;
@Input() id;
st;
@Input() coursestat: string;
constructor(private getDt: InputDataService) {
} …Run Code Online (Sandbox Code Playgroud) 我的客户正在进行ajax调用
{{
function callNode(){
console.log("I am called");
var data = {"emailId":"gopal@gmail.com"};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
/* data: {
blob: {wob:"1",job:"2", ar:[1,2,{a:'b'}]}
},*/
contentType: "application/javascript",
//contentType: "application/x-www-form-urlencoded",
dataType:'json',
url: 'http://localhost:3000/notification',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
},
error: function(error) {
console.log("some error in fetching the notifications");
}
});
}
}}
Run Code Online (Sandbox Code Playgroud)
我可以在我的app.js中获取此请求,但无法获取我传递的数据,我试图搜索但没有任何工作
{{
app.post('/notification', function(req, res) {
JSON.stringify(req.params);
/*
var body;
req.on('data', function(chunk) {
console.log("Received body data:");
body += chunk;
});
// the end event tells you that you have entire body …Run Code Online (Sandbox Code Playgroud) 我目前正在使用node.js处理Web应用程序,我无法解决库异步的上下文问题.
这是我的应用程序的代码示例:
notification.prototype.save = function (callback) {
async.parallel([
// Save the notification and associate it with the doodle
function _saveNotification (done) {
var query = 'INSERT INTO notification (notification_id, user_id, doodle_id, schedule_id) values (?, ?, ?, ?)';
notification.db.execute(query, [ this.notification_id, this.user_id, this.doodle_id, this.schedule_id ], { prepare : true }, function (err) {
return done(err);
});
console.log("SAVE NOTIFICATION");
console.log("doodle_id", this.doodle_id);
}.bind(this),
// Save notification for the users with the good profile configuration
function _saveNotificationForUsers (done) {
this.saveNotificationForUsers(done);
}.bind(this)
], function (err) …Run Code Online (Sandbox Code Playgroud) 我正在尝试做一个响应式画布.我所有的测试都是用600x600帆布做的,并且它的高度和宽度都能正常工作并正确地绘制每一行.问题是我试过这个:
#myCanvas {
background-color: #ffffff;
border:1px solid #000000;
min-height: 600px;
height: 100%;
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
只是为了记录,myCanvas在sm-col-8中.
它在我的笔记本电脑上看起来不错,在我的手机上看起来不错但是(因为我的绘画()功能,因为它正在考虑一个正方形)画面开始更像是在左下角(附近),它应该从右上角.
所以,我不想改变我的draw()函数,但我正在寻找的是重新缩放画布大小.我的意思是:如果我在笔记本电脑/平板电脑上... 600x600,显示它的大小,但如果我在我的手机上有384x640显示它像300x300?我不知道这是否是一个很好的解决方案.
我的绘画功能:
function drawLines(lines,i,table,xtotal,ytotal){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var xIni;
var xFin;
var yIni;
var yFin;
xIni = (c.width*parseInt(lines[i][1])/xtotal);
yIni = (c.height*parseInt(lines[i][2])/ytotal);
xFin = (c.width*parseInt(lines[i][3])/xtotal);
yFin = (c.height*parseInt(lines[i][4])/ytotal);
ctx.beginPath();
ctx.moveTo(xIni,c.height-yIni);
ctx.lineTo(xFin,c.height-yFin);
ctx.lineWidth=4;
ctx.strokeStyle = colorAleatorio();
ctx.stroke();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的服务中编写一个非常简单的函数,它将创建一个FileReader,读取我发送它的小图像文件,并将此结果返回给我的控制器.文件到我的服务就好了.它到达我的控制器并只记录一个空白行.我假设我在某种程度上弄乱了这个承诺部分.那里我哪里错了?
服务功能 -
this.fileRead = function(file) {
var deferred = $q.defer();
var reader = new FileReader();
reader.readAsDataURL(file);
deferred.resolve(reader.result);
return deferred.promise;
};
Run Code Online (Sandbox Code Playgroud)
控制器功能 -
$scope.onFileSelect = function($files) {
MyService.fileRead($files[0])
.then(function(result) {
console.log(result);
});
};
Run Code Online (Sandbox Code Playgroud) 当使用NPM请求模块的request.defaults API时,是否有人知道我可以将一个函数作为请求头传递,以便每次发出传出请求时函数的结果都成为头值?
即
request.defaults({
headers:{datestamp:() => new Date()
})
Run Code Online (Sandbox Code Playgroud) node.js ×5
javascript ×4
promise ×2
ajax ×1
android ×1
angular ×1
angularjs ×1
arrays ×1
asynchronous ×1
bind ×1
canvas ×1
compare ×1
css ×1
ecmascript-6 ×1
html5 ×1
jquery ×1
npm ×1
npm-request ×1
php ×1
post ×1
postgresql ×1
request ×1
search ×1
tcp ×1