我已经看到许多在 Angularjs 中格式化电话号码输入字段的解决方案,但我在 Angular 7 上找不到任何内容。我本质上想要的是让用户在文本字段中输入以下内容:
123456789
以及用于将输入格式化为的文本字段:
(123) 456-789
我该怎么做呢?我找到了以下正则表达式来验证它:
^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$
Run Code Online (Sandbox Code Playgroud) 我想使用 Jest 和 Enzyme 对 Next.js 的 getServerSideProps
功能进行测试。该函数如下所示:
export const getServerSideProps: GetServerSideProps = async (context) => {
const id = context?.params?.id;
const businessName = getBusinessName(id);
return {
props: {
businessName: response.data?.name,
businessID: id,
},
};
};
Run Code Online (Sandbox Code Playgroud)
但是,由于我context
在函数中使用参数,因此我需要将上下文传递到测试中。我现在的测试看起来像:
it("check on good case", () => {
const value = getServerSideProps(/*I'm not sure what to put here*/);
expect(value).toEqual({props: {businessName: "Name", businessID: "fjdks"}})
});
Run Code Online (Sandbox Code Playgroud)
我的问题是我应该将什么传递给上下文参数。我知道它的类型必须是:GetServerSidePropsContext<ParsedUrlQuery>
。但我不确定如何创建该类型。我可以将什么传递到函数中,同时也允许我id
在参数中添加值?
我想在 Flutter 中向ClipRRect添加阴影。我希望它看起来像这样:
但是当我尝试构建它时,我得到了这样的结果:
阴影穿过整个框而不是 ClipRRect 区域。这是我的代码:
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Color(0x54000000),
spreadRadius: 10,
blurRadius: 2,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(250)),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
end: Alignment.bottomCenter,
begin: Alignment.topCenter,
colors: [
Theme.of(context).primaryColor,
Color(0xff995DFF)
])),
height: 500,
width: MediaQuery.of(context).size.width,
),
),
)
],
)
Run Code Online (Sandbox Code Playgroud)
不知何故,阴影需要正好位于 ClipRRect 上。谢谢你的帮助
我有一个程序,我从 Firebase 的云 Firestore 获取用户列表,并使用 Flutter 中的 StreamBuilder 将它们显示在 Listview 中。用户数量会很大,我想在我的流构建器中实现一个搜索字段,它将查询与我的搜索字段匹配的结果。我希望它看起来像这样:
--照片来源:https ://blog.usejournal.com/flutter-search-in-listview-1ffa40956685
我的 Streambuilder 如下所示:
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('users')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: Column(
children: <Widget>[
CircularProgressIndicator(),
Text('Loading'),
],
),
);
default:
return Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListView.separated(
shrinkWrap: true,
padding: EdgeInsets.all(10.0),
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
return buildUserRow(snapshot.data.documents[index]);
},
separatorBuilder: (context, index) {
return Divider();
}, …
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用了一个 Angular Material Date Picker 应用程序,它是一个预订表格。我想要的是让用户通过Date Picker选择日期。日期选择器将有一个过滤器,显示哪些日期是开放的,哪些不是。为了让日期选择器知道哪些日期可用,它必须调用我的一项服务,该服务返回一个Observable。这是我的日期选择器的 HTML 代码:
<mat-form-field>
<label>
<input matInput [matDatepickerFilter]="dateFilter" required [matDatepicker]="picker" placeholder="Choose a date"
formControlName="date">
</label>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
和日期过滤器():
dateFilter = (d: Date): boolean => {
if(monthIsSame(d) {
..// have a return statement that process a global variable: 'month: Day[]'
} else {
// the user hit the arrow at the top that switches months
//
// have a process that sets the 'month' variable …
Run Code Online (Sandbox Code Playgroud) 我想使用正则表达式查询 Firestore 中的文档。这是因为为了将搜索功能添加到我的 Flutter 应用程序中,我需要能够基于搜索创建查询。例如,如果用户输入:“alice”——我将有一个看起来像这样的正则表达式,(?i)alice
并且我将在 firestore 中查询名称字段满足此正则表达式的任何文档,无论是 Alice、Alice Doe 还是 Doe Alice。我正在寻找一个如下所示的查询:
Firestore.instance.collection('people')
.where('name', matchesRegex: '(?i)alice')
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。我觉得这是一个非常基本的功能,但我在文档中找不到它。我真的无法获取所有文档并据此进行搜索,因为集合非常大,而且我不想阅读那么多文档。
I am using Docker to run some containers on Windows 10, and when I was done I noticed an application named vmmem was using almost all of my ram: ~12GB. According to this it is because of Docker and it said if I closed all docker images and containers it would stop. So I stopped and removed all Docker containers and images by the following batch file:
@echo off
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker rm …
Run Code Online (Sandbox Code Playgroud) 我正在使用 mailgun 模板和 Go 来发送电子邮件。但是,当我的模板字段中的文本\n
不包含添加换行符时。我的基本代码如下所示:
message := m.mg.NewMessage(sender, subject, body, recipient)
message.SetTemplate("my-template")
_ = message.AddTemplateVariable("myText", event.Text)
// ... Code for sending
Run Code Online (Sandbox Code Playgroud)
我看到这个关于用换行符发送邮件的答案,但是当我像下面这样实现它时:
_ = message.AddTemplateVariable("myText", strings.ReplaceAll(event.Text, "\\n", "<br />"))
Run Code Online (Sandbox Code Playgroud)
该电子邮件正文包含<br />
文本,但不包含换行符。
我还尝试在模板的 CSS 中添加以下字段:white-space: pre-wrap;
但仍然没有中断。感谢您使用 Golang 将换行符添加到 Mailgun 模板的任何帮助。
我有一个使用 Material Design 的 Flutter 项目,当我浏览路线时,appbar 将显示后退按钮。最近刚在我的项目中实现了一个抽屉,抽屉图标覆盖了后退图标。我基本上想撤消此操作,为某些屏幕显示后退按钮,并为其他屏幕显示菜单按钮,就像我定义具有showIcon: false
属性的抽屉一样?我知道这篇文章是一个类似的问题,但没有显示问题或解决方案的代码......我的抽屉看起来像这样:
return Scaffold(
//appbar is here
appBar: AppBar(
title: Text("Title"),
),
drawer: drawer,
body: _buildBody(),
);
Run Code Online (Sandbox Code Playgroud)
我在这里定义抽屉:
var drawer = Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
//My listTiles and UserAccountsDrawerHeader are removed for simplicity
],
),
);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
我有一个 Flutter Web 项目。我有以下 HTML 脚本需要放入HtmlElementView
:
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID"></script>
<script>paypal.Buttons().render('body');</script>
Run Code Online (Sandbox Code Playgroud)
从这里。我试过这个:
Widget build(BuildContext context) {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'paypal-button',
(int viewId) => IFrameElement()
..width = '500'
..height = '500'
..src = '''
<div id="paypal-button-container"></div>
<script src="https://paypal.com/sdk/js?client-id=MY_CLIENT_ID"></script>
<script>
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to …
Run Code Online (Sandbox Code Playgroud) flutter ×5
angular ×2
firebase ×2
typescript ×2
dart ×1
datepicker ×1
docker ×1
flutter-web ×1
format ×1
go ×1
jestjs ×1
mailgun ×1
next.js ×1
paypal ×1
phone-number ×1
reactjs ×1
windows ×1