我正在 Next.js 中处理API 路由,每个路径的结构如下:
import { NextApiRequest, NextApiResponse } from "next";
export default async (req: NextApiRequest, res: NextApiResponse) => {
const { query } = req;
try {
switch (req.method) {
case "GET":
// Do some GET stuff
res.status(200).send(result);
break;
case "POST":
// Do some POST stuff
res.status(200).send(result);
break;
default:
// No Matched Method
res.status(405).send("Method Not Allowed");
break;
}
} catch (e) {
// Unprocessable Entity
res.status(422).send(e);
}
};
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,default案例和catch零件将在所有文件中重复。所以,我想知道:
如果没有内置支持,这是我的解决方案: …
我正在将 HTTP 触发器函数部署到 Azure Function,但是当我尝试访问其中的条目时,process.env它会返回undefined. 它可以在本地模拟器中运行,但在部署到 Azure 上时不能运行。
我已经用一个非常简单的 HTTP 函数对其进行了测试。
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
context.log(process.env.GCP_SERVICE_ACCOUNT_EMAIL);
context.res = {
body: process.env.GCP_SERVICE_ACCOUNT_EMAIL,
};
};
export default httpTrigger;
Run Code Online (Sandbox Code Playgroud)
当本地运行时,它会输出值设置local.settings.json
[2021-09-11T13:41:27.737Z] Executing 'Functions.HttpTrigger' (Reason='This function was programmatically called via the host APIs.', Id=b9a303aa-5d14-403c-b841-4851f00beb65)
[2021-09-11T13:41:27.768Z] service_account@local.settings.json
[2021-09-11T13:41:27.848Z] Executed 'Functions.HttpTrigger' (Succeeded, Id=b9a303aa-5d14-403c-b841-4851f00beb65, Duration=126ms)
Run Code Online (Sandbox Code Playgroud)
但是,当在 …
我有两种不同的菜单布局.我想在单击按钮时更改运行时的膨胀菜单.
最初菜单设置为@menu/navigation.我希望它更改@menu/navigation2为单击按钮时.
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="th.ac.sd.sdschoolas.MainActivity">
<FrameLayout
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<WebView
android:id="@+id/web_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="152dp"
android:layout_height="158dp"
android:layout_x="23dp"
android:layout_y="46dp"
app:srcCompat="@mipmap/logo"
android:padding="20dp"/>
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
菜单/ navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav1"
android:icon="@mipmap/homeicon"
android:title="@string/title_home" />
<item
android:id="@+id/nav2"
android:icon="@mipmap/newsicon01"
android:title="@string/title_news" />
<item
android:id="@+id/nav3"
android:icon="@drawable/ic_calendar_page_empty"
android:title="@string/title_cal" />
<item
android:id="@+id/nav4"
android:icon="@drawable/ic_chat_bubbles"
android:title="@string/title_sms" />
<item
android:id="@+id/nav5"
android:icon="@mipmap/more"
android:title="@string/title_more" />
</menu>
Run Code Online (Sandbox Code Playgroud)
菜单/ …
我想使用Angular Google Maps在 Google Maps 上放置一个标记,我的坐标来自 JSON 文件,当在 Angular 中解析它时,它变成了一个字符串。
Angular Google Maps 不支持坐标数字字符串。所以它需要是数字。
标记.json
[
{
"id":"1",
"lat":"13.751814",
"lon":"100.501060"
},
{
"id":"2",
"lat":"13.738445",
"lon":"100.516805"
},
{
"id":"3",
"lat":"13.730209",
"lon":"100.779991"
}
]
Run Code Online (Sandbox Code Playgroud)
地图.componentnet.ts
import { Component, OnInit } from '@angular/core';
import {Http, Response} from '@angular/http';
@Component({
selector: 'app-maps',
templateUrl: './maps.component.html',
styleUrls: ['./maps.component.css']
})
export class MapsComponent implements OnInit {
private data;
constructor(private http:Http){
}
ngOnInit(){
this.getData();
}
getData(){
this.http.get('/localhost/marker.json')
.subscribe(res => this.data = res.json());
}
}
Run Code Online (Sandbox Code Playgroud)
地图.component.html
<agm-map …Run Code Online (Sandbox Code Playgroud) 我从应用程序中删除了操作栏,所以我需要创建按钮来自己打开抽屉 Activity 上的按钮工作正常但是当我在片段应用程序中使用它时停止工作(当我调用片段时)
我在 Activity 中使用的代码(工作正常的代码)
ImageButton btn = (ImageButton)findViewById(R.id.drawerButton);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.openDrawer(Gravity.START);
}
});
Run Code Online (Sandbox Code Playgroud)
fragment_achievements.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="layout.AchievementsFragment">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="28dp"
android:layout_height="29dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_menu_button" />
<WebView
android:id="@+id/web_ach"
android:layout_width="409dp"
android:layout_height="602dp"
android:layout_marginBottom="-9dp"
android:layout_marginLeft="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_editor_absoluteY="56dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
成就片段.java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView; …Run Code Online (Sandbox Code Playgroud) 我目前正在使用这样的语法:
print(*list(map(lambda a: [something to do], input())))
Run Code Online (Sandbox Code Playgroud)
如果返回类型是字符串但不是数字,它工作正常.
例如.以下脚本用于在两个不同版本中查找三个的平方根
print(*list(map(lambda a: int(a)**(1/3), input())))
Run Code Online (Sandbox Code Playgroud)
和
SQRT = lambda a: a**(1/3)
print(SQRT(int(input())))
Run Code Online (Sandbox Code Playgroud)
当我输入9两个返回2.080083823051904(这是正确的)但是当我输入10第一个返回1.0 0.0和2.154434690031884第二个返回时.
我想知道有什么方法可以直接从lambda打印,返回一个数字而不会导致上面解决的问题?
android ×2
javascript ×2
node.js ×2
android-menu ×1
angular ×1
azure ×1
express ×1
json ×1
next.js ×1
python ×1
python-3.x ×1
terraform ×1
typescript ×1