如何在php中合并n个数组.我的意思是我怎么能这样做:
array_merge(from : $result[0], to : $result[count($result)-1])
OR
array_merge_recursive(from: $result[0], to : $result[count($result) -1])
其中$result包含多个数组的数组在哪里:
$result = Array(
0 => array(),//associative array
1 => array(),//associative array
2 => array(),//associative array
3 => array()//associative array
)
Run Code Online (Sandbox Code Playgroud)
我的结果是:
$result = Array(
0 => Array(
"name" => "Name",
"events" => 1,
"types" => 2
),
1 => Array(
"name" => "Name",
"events" => 1,
"types" => 3
),
2 => Array(
"name" => "Name",
"events" => 1,
"types" => 4
), …Run Code Online (Sandbox Code Playgroud) 我创建了Android app使用cordova 2.6.0.我已经menu在我的应用程序中使用html标记实现了一项功能,并jQuery在与设备进行交互时切换menubutton.但我无法想出达到以下要求,表现得像本机应用程序.
需求
如果是,menu应隐藏在按下设备上.如果不可见,那么现在应该正常行动,也就是它应该是或应该去.backbuttonmenuvisiblemenubackbuttonexitappback history
这是我的代码
document.addEventListener('deviceready', function(){
document.addEventListener('menubutton', function(){
//Toggle Menu
//Which is working fine
});
document.addEventListener('backbutton', function(){
if(menu is visible) {
//Hide the menu
//This is also working fine
return false;
}
//BUT the default action of backbutton has gone. It cannot exit the app , neither it brings to back history.
//return true;
//I …Run Code Online (Sandbox Code Playgroud) const APP_ROUTES: RouterConfig = [
{
path: 'app/home',
component: HomeComponent,
data: {
name: 'Home'
}
}
]
Run Code Online (Sandbox Code Playgroud)
如果我有如上所示的路由配置,我如何data从某个指令访问其属性.
@Directive({
name: 'hello'
})
class HelloDirective {
@Input('routerLink') link: string[];
ngOnInit() {
//HOW CAN I GET ROUTE AND ITS DATA FROM PATH/URL ???
//const magicallyGrabbedRoute = pleaseGiveMeMyRouteFrom(this.link);
//const myData = magicallyGrabbedRoute.data;
}
}
<a hello [routerLink]="['app/home']"> Go Home </a>
Run Code Online (Sandbox Code Playgroud)
在hello指令中如何获取routerLink属性值的路由配置?
我在猫鼬中有以下模型:
var RelationSchema = new Schema({
user : {type:ObjectId, ref:'users'}
, type : String
, remarks : String
, createdOn : {type:Date, default:Date.now}
}, {_id:false});
var UserRelationSchema = new Schema({
user : {type:ObjectId, ref:'users'}
, relations : [RelationSchema]
});
var UserRelation = mongoose.model('user_relations', UserRelationSchema);
Run Code Online (Sandbox Code Playgroud)
每次我使用相同的值运行以下命令时,都会将新的子文档添加到数组中relations。如果我createdOn从架构中删除字段RelationSchema,那么它就可以正常工作。
UserRelation.update(
{"user":<ObjectId>}
, {
$addToSet: {
"relations": {"user":<ObjectId>,"type":<String>}
}
, {upsert:true}
});
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如何addToSet使用日期/时间字段?
从同一软件包安装多个npm模块有什么捷径吗?
我的意思是,而不是:
npm i @angular/common @angular/compiler @angular/core @angu
lar/forms @angular/http @angular/platform-browser @angular/platform-browser-dynamic @angular/router @angular/router
-deprecated -S
我可以做类似的事情吗?
npm i @angular/{common, compiler, core, forms, platform-browser, platform-browser-dynamic, router, router-deprecated} -S
我想建三捆:main.js,vendor.js和polyfill.js.polyfill.js文件应包含polyfill.js文件中定义的模块.vendor.js应该通过提取从npm(node_modules)导入的所有依赖项来动态创建文件.最后main.js应该包含而不是polyfill和vendor模块,这本质上是我的应用程序代码.
polyfill.js
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
Run Code Online (Sandbox Code Playgroud)
main.js
import { NgModule, ApplicationRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Store } from '@ngrx/store';
@NgModule([
imports: [...]
])
class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
我写了下面的webpack配置,但总是得到以下错误:
"CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (main)",
"CommonsChunkPlugin: While running in …Run Code Online (Sandbox Code Playgroud) 有人可以将以下波兰表示法转换为其SQL对应物:
['|', '&', ('is_company','=', True),('parent_id', '=', False),('company_name', '!=', False),('company_name', '!=', '')]
我的猜测是:
is_company = True OR parent_id = False AND company_name <> False AND company_name <> ''
无论我多么努力地理解它,我都无法得到这种符号的概念.请帮忙.
UPDATE
我试图将上述表示法扩展为:
((is_company = True AND parent_id = False) OR company_name <> False) AND company_name <> '' AND customer_type_id <> False
我有以下型号:
var VoteSchema = new Schema({
up : Boolean
, createdBy:{type:ObjectId, ref:'users'}
, createdOn : {type:Date, default:Date.now}
});
var QuestionSchema = newSchema({
title:String
, description:String
, votes : [VoteSchema]
, createdBy:{type:ObjectId, ref:'users'}
, createdOn : {type:Date, default:Date.now}
});
var Question = mongoose.model('questions',QuestionSchema);
Run Code Online (Sandbox Code Playgroud)
假设user1已登录用户并且question1是当前/查看问题.用户可以随时upvote({up:true})或downvote({up:false})提出问题.如果没有投票给其他投票,我怎么能add成为新人.voteuser1question1update
我已经能够编写以下代码行:
QuestionSchema.statics.castVote = function(questionId, vote) {
//NOTE : vote.createdBy equalsto loggedInUserID
Q.nbind(Question.findOne, Question)({
$and:[
{_id:questionId},
{'votes.createdBy':vote.createdBy}
]
}).then(function(doc) …Run Code Online (Sandbox Code Playgroud) import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
fun main() {
val jsonString: String = """{
"jsonrpc": "2.0",
"id": null,
"result": [
{
"id": 1,
"name": "Lekhnath Rijal"
},
{
"id": 2,
"name": "Administrator"
}
]
}"""
val body1 = Gson().fromJson<RpcResult<List<Partner>>>(jsonString, object: TypeToken<RpcResult<List<Partner>>>(){}.type)
println(body1.result[0].name) // prints Lekhnath Rijal // - As expected
val body2 = fromJson<RpcResult<List<Partner>>>(jsonString)
println(body2.result[0].name) // throws Exception as stated below after this code snippet
}
fun <T> fromJson(json: String?): T {
return Gson().fromJson<T>(json, object: TypeToken<T>(){}.type)
}
data class RpcResult<T>(
val jsonrpc: …Run Code Online (Sandbox Code Playgroud) 我通过将其原始名称重命名为来保存用户上传userID + '_' + new Date().getTime() + fileExt.我将文件属性存储在mongodb集合中:
{
name : String //generated name
, originalName : String //its original name
...
}
Run Code Online (Sandbox Code Playgroud)
现在当用户请求下载文件时,我必须向用户提供文件的原始名称(在db中保存,因此没有问题).
对于以下请求
GET /users/:userId/uploads/:fileId?type=download
我有这个处理程序
//the mongoose query
UserUpload.findById(req.params.fileId).exec(function(err, doc){
var fileLocation = __dirname + '/public/uploads/users/' + req.params.userId + '/' + doc.name;
if(req.query.type && req.query.type == 'download') {
// I don't know what should I do now
// Downloader.download(fileLocation, newName);
}
});
Run Code Online (Sandbox Code Playgroud)
是否可以显式地将async管道提取的值分配给模板变量?
在以下示例userList中分配length了获取的值.我希望它取而代之的是取得的结果.我还想noResult根据获取结果的长度显示用户列表或模板消息.
<ng-template #noResult> <p> No result to display</p> </ng-template>
<div *ngIf="(userList$ | async)?.length; else noResult; let userList">
<ul *ngFor="let user of userList">
<li> {{ user.email }} </li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud) angular ×2
mongodb ×2
mongoose ×2
node.js ×2
android ×1
array-merge ×1
back-button ×1
cordova ×1
download ×1
express ×1
generics ×1
gson ×1
javascript ×1
jquery ×1
json ×1
kotlin ×1
npm ×1
npm-install ×1
odoo ×1
odoo-10 ×1
php ×1
python ×1
static-files ×1
typescript ×1
webpack ×1
webpack-2 ×1
xml ×1