将整个 React 组件存储在组件状态或 redux 状态中是一个好习惯吗?是的,它是可选的,因为我们可以在状态中存储字符串并有条件地渲染组件,但在某些情况下,将组件存储在状态中更简单。
例如,
const [ components ] = useState([
{ id: 1, component: <Login />, title: `Login` },
{ id: 2, component: <Register />, title: `Register` },
])
Run Code Online (Sandbox Code Playgroud)
但组件可能很大,我想知道这是否有什么区别。这是一个不好的做法吗?
以前,我使用jQuery处理问题如下:
$("#textInput").keydown(function (e) {
return e.which !== 32;
});
Run Code Online (Sandbox Code Playgroud)
你会如何使用新的Angular和Typescript来处理它?
它有内置管道吗?
data = [
{id: 5, name: 'Roger'},
{id: 5, name: 'Mark'},
{id: 5, name: 'Zach'},
{id: 5, name: 'Mark'},
{id: 5, name: 'Roger'},
];
<ul>
<li *ngFor="let datum of data">
{{datum.name}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
Output
Desired Output
请考虑以下数据:
food = {
id: 1,
name: 'Pizza',
price: 16
};
orders = [
{ food_id: 2, table_id: 5 },
{ food_id: 2, table_id: 5 },
{ food_id: 1, table_id: 5 },
{ food_id: 3, table_id: 5 },
{ food_id: 1, table_id: 5 }
];
Run Code Online (Sandbox Code Playgroud)
我想从orders数组匹配中删除单个项目food_id.这是我试过的:
removeFoodOrder(food: Food): void {
for (let order of this.orders) {
let match = this.orders.filter((order) => order.food_id == food.id);
match ? this.orders.splice(this.orders.indexOf(order), 1) : null;
break;
}
console.log(this.orders);
}
Run Code Online (Sandbox Code Playgroud)
如果我调用removeFoodOrder(food) …
就像引导,离子(离子型3)让我们调整列的宽度基于使用屏幕大小col-sm-8,col-md-6,col-lg-4.引导还配备了像类visible-xs,hidden-sm等等,使我们能够展示或根据屏幕大小隐藏的内容.Ionic 3是否附带任何可以让我们这样做的东西?
从0.14切换到v15.5时,React Router的链接标记出错.这在前一版本中运行良好,并在后者中引发以下错误.
警告:React.createElement:type无效 - 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:undefined.您可能忘记从其定义的文件中导出组件.检查渲染方法
Navbar.
navbar.js
import React, { Component } from 'react';
import Link from 'react-router-dom';
class Navbar extends Component
{
render()
{
return (
<nav className="nav">
<Link className="btn btn-primary btn-block" to="/about">
About Us
</Link>
</nav>
);
}
export default Navbar;
Run Code Online (Sandbox Code Playgroud)
index.js
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import HomePage from './components/homepage/homepage';
import AboutPage from './components/aboutpage/aboutpage';
render
(
<BrowserRouter>
<Switch>
<Route path="/about" component={AboutPage} />
<Route …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 PHP 的 intl 扩展名将数量转换为单词。例如,
第1450章一千四百五十
我正在使用 Laravel 5.4,它在带有 PHP 5.6.24 的 XAMPP 3.2.2 服务器上运行。
正如在类似问题中提到的,我已经intl通过取消注释extension=ext/php_intl.dllPHP.ini 文件中的行来启用PHP 扩展,然后重新启动我的服务器。
$inWords = new \NumberFormatter('en', \NumberFormatter::SPELLOUT);
echo $inWords->format(1450);
Run Code Online (Sandbox Code Playgroud)
产生错误:
FatalErrorException:未找到“NumberFormatter”类
我猜这与 Laravel 无关,但与 PHP 无关。有谁知道问题的解决方案?谢谢你的时间。
我刚刚开始编写一个我从中克隆的新的angular2应用程序
https://github.com/angular/quickstart
为什么我收到此错误?
app/app.component.ts(8,3):error TS2345:类型'{moduleId:string; selector:string; templateUrl:string; 指令:string []; }'不能分配给'Component'类型的参数.对象文字只能指定已知属性,"组件"类型中不存在"指令".
app.component.ts
import { Component } from '@angular/core';
import { NavbarComponent } from './components/navbar/navbar.component';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
directives: [NavbarComponent]
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)
navbar-component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'navbar',
templateUrl: `navbar.component.html`,
})
export class NavbarComponent { }
Run Code Online (Sandbox Code Playgroud) 我想在地图上显示地点名称,而不是标签 A 和 B。如何在 Google Maps Directions API 中执行此操作?例如, just Startand Endor Miami Portto Miami Tower。
CODE
let directionsDisplay;
let directionsService = new google.maps.DirectionsService();
let map;
directionsDisplay = new google.maps.DirectionsRenderer();
let myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
let mapArea = document.getElementById("map_canvas_track_order");
map = new google.maps.Map(mapArea, myOptions);
directionsDisplay.setMap(map);
let start = `25.757928, -80.192897`;
let end = `25.771969, -80.191235`;
let request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response); …Run Code Online (Sandbox Code Playgroud) javascript google-maps google-maps-api-3 google-maps-markers
我正在尝试使用 Lodash 的debounce功能来消除文本输入字段更改的抖动。
import React from "react";
import debounce from 'lodash.debounce';
const Input = () => {
const onChange = debounce((e) => {
const { value } = e.target;
console.log('debounced value', value)
}, 1000)
return (
<input type="text" onChange={ onChange } />
)
};
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出以下错误:
警告:出于性能原因重用此合成事件。如果您看到此内容,则说明您正在访问已发布/无效的合成事件的属性目标。这被设置为空。如果必须保留原始合成事件,请使用 event.persist()。
未捕获的类型错误:无法读取 null 的属性“值”
什么是正确的实施?
angular ×4
reactjs ×3
javascript ×2
typescript ×2
bootstrap-4 ×1
css ×1
debouncing ×1
ecmascript-6 ×1
google-maps ×1
ionic3 ×1
laravel ×1
laravel-5.4 ×1
lodash ×1
php ×1
react-router ×1
redux ×1