所以我参加了Michael Hartl的Rails教程,第12章,列出了12.7.
我已经写了一些测试,但是所有的54个测试最终都出现了错误.前几个是:
ERROR["test_should_require_a_followed_id", RelationshipTest, 0.686335129]
test_should_require_a_followed_id#RelationshipTest (0.69s)
ActiveRecord::RecordNotUnique: ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", "updated_at", "id") VALUES (1, 1, '2015-03-10 16:12:17', '2015-03-10 16:12:17', 298486374)
ERROR["test_should_be_valid", RelationshipTest, 0.835273632]
test_should_be_valid#RelationshipTest (0.84s)
ActiveRecord::RecordNotUnique: ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", "updated_at", "id") VALUES (1, 1, '2015-03-10 16:12:17', '2015-03-10 16:12:17', 298486374)
ERROR["test_should_require_a_follower_id", RelationshipTest, 0.988648702]
test_should_require_a_follower_id#RelationshipTest (0.99s)
ActiveRecord::RecordNotUnique: ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails ruby-on-rails-3 railstutorial.org ruby-on-rails-4
使用 NextJS,我尝试使用具有toandas字段的对象路由到另一个页面:
export const routes = {
'BrowseList' : {
'to' : '/apps/Browse/list',
'as' : '/browse/list'
}
// ....
}
Run Code Online (Sandbox Code Playgroud)
然后像这样导入和使用:
import { routes } from './__routes';
import Router from 'next/router';
// ....
const { to, as } = routes.BrowseList;
Router.push(to, as);
Run Code Online (Sandbox Code Playgroud)
这一切都有效。我的困境是我试图在附加查询参数时做类似的事情。我正在尝试根据文档遵循此示例:
Router.push({
pathname: '/about',
query: { name: 'Zeit' },
})
Run Code Online (Sandbox Code Playgroud)
我尝试过的(不起作用):
Router.push({
pathname : to,
as,
query : { user_id: this.props.data.member.user.id },
});
Run Code Online (Sandbox Code Playgroud)
这给了我一个控制台警告
Unknown key passed via urlObject into url.format: as …Run Code Online (Sandbox Code Playgroud) 我有一个可重用的输入/复选框组件,它接受一个label道具:
<Checkbox
label="I have read and understood the Terms of Service and consent to the Privacy Policy"
/>
Run Code Online (Sandbox Code Playgroud)
和我的复选框的渲染:
<label>
<input
type='checkbox'
disabled={this.props.disabled}
onChange={this.handleChange}
checked={this.props.value}
placeholder={this.props.placeholder}
/>
{this.label}
</label>
Run Code Online (Sandbox Code Playgroud)
但是我希望标签接受类似的东西
<Checkbox
label="I have read and understood the <a href="http://....">Terms of Service</a> and consent to the <a href="http://....">Privacy Policy</a>"
/>
Run Code Online (Sandbox Code Playgroud)
并有文字Terms of Service和Privacy Policy链接。然而这行不通。
我是否必须使用类似的东西dangerouslySetInnerHtml来实现这样的目标?从我理解使用innerHTML是一种风险,不是吗?
修改我的组件以便能够添加这样的链接的最佳方法是什么?
OutlinedButton我正在尝试更改我的边框,main.dart但它似乎不起作用。我环顾四周,似乎我需要添加BorderSide. 这就是我的outlinedButtonTheme样子:
outlinedButtonTheme: OutlinedButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) {
return AppColors.SecondaryButtonPressed;
}
return AppColors.SecondaryButton;
},
),
minimumSize: MaterialStateProperty.all<Size>(Size(335, 60)),
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
side: BorderSide(
style: BorderStyle.solid,
color: AppColors.Primary,
width: 1), // <-- this doesn't work?
borderRadius: BorderRadius.all(Radius.circular(12)),
)),
foregroundColor: MaterialStateProperty.all<Color>(
AppColors.SecondaryButtonText),
textStyle: MaterialStateProperty.all<TextStyle>(TextStyle(
color: AppColors.SecondaryButtonText,
fontSize: 14 * FONT_SCALE_FACTOR,
fontWeight: FontWeight.w600,
)),
),
),
Run Code Online (Sandbox Code Playgroud)
如上所示,BorderSide 所在位置。看起来这根本不起作用。
我有一个对象数组:
(7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
Run Code Online (Sandbox Code Playgroud)
以及id我想要在这个对象数组中查找的值.
该 id = "c2a6e78d2bc34cffb08d6e17a5631467"
然后使用,这个id,我想回到我那个与我所拥有的对象id相匹配的对象.在那之后,我只是想获得该对象的不同属性,比如object.createdAt.
我的问题是:是否可以使用.map这个数组,然后用它id来返回包含并匹配它的一个对象id?到目前为止我已经习惯了map,filter但也许我用错了方法......
我环顾了 Stackoverflow,普遍的共识似乎是添加到我的服务器文件中。
虽然我想知道 NextJS 的动态路由是否可以实现。
我正在尝试实现一条看起来像这样的路线:
/categories/:id/articles/:id
Run Code Online (Sandbox Code Playgroud)
我试过做这样的事情
- pages
- categories
- [id]
- :id.js
- articles
- :id.js
Run Code Online (Sandbox Code Playgroud)
无济于事,所以也许这不是最好的方法。我能在不接触服务器的情况下实现这样的目标吗?
这非常微妙,但在 Figma 中,CSS 看起来像这样:
根据figma的CSS:
background: radial-gradient(50% 50% at 50% 50%, rgba(255, 255, 255, 0.116) 0%, rgba(255, 255, 255, 0) 100%), #15636D;
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的事情,但最终看起来很遥远:
gradient: RadialGradient(
colors: [
Color.fromRGBO(255, 255, 255, 0.116),
Color.fromRGBO(152, 70, 242, 0),
AppColors.primary, // #15636D
],
),
Run Code Online (Sandbox Code Playgroud)
有没有办法调整这个分布?
我的后备计划是,如果其他方法都失败了,就把它变成背景图像。
在React上下文中,我试图渲染一些具有如下结构的对象:
const regions = [
{
displayName: 'NYC',
locations: [
{name: 'thing', isVisible: false},
{name: 'thing1', isVisible: false},
{name: 'thing3', isVisible: false},
],
},
{
displayName: 'Seattle',
locations: [
{name: 'thing', isVisible: true},
{name: 'thing1', isVisible: true},
{name: 'thing3', isVisible: true},
],
....
},
....
];
Run Code Online (Sandbox Code Playgroud)
我的问题是第一个对象与所有对象的上下文,isVisible: false如果所有isVisible值都为假,是否可以删除整个对象?基本上使用这个例子,这个对象:
{
displayName: 'NYC',
locations: [
{name: 'thing', isVisible: false},
{name: 'thing1', isVisible: false},
{name: 'thing3', isVisible: false},
],
},
Run Code Online (Sandbox Code Playgroud)
将被删除.
如果是这样,怎么样?如果没有,这是否可以实现?有没有其他解决方案?
我有一个已经像这样构建的组件:
const Banner = ({ image, heading, text }) => (
<Container>
<Background src={image}>
<BannerContent>
<h1>{heading}</h1>
<h2>{text}</h2>
</BannerContent>
</Background>
</Container>
);
const BannerContent = styled.div`
h1 {
font-size: 24px;
}
h2 {
font-size: 16px;
}
`;
Run Code Online (Sandbox Code Playgroud)
并且我试图覆盖和的样式,h1并h2在另一个组件中添加新样式,如下所示:
const PageBanner = styled(Banner)`
h1 {
font-size: 20px;
width: ...
}
h2 {
font-size: 13px;
width: ...
}
`;
Run Code Online (Sandbox Code Playgroud)
但是,这些都没有发生。我以为是因为它嵌套在里面?我可以覆盖样式吗?还是我应该建立一个类似的组件?
所以我有一个像这样的对象:
const maxValues = {
flexMaxSeatYear: 16270,
flexMaxTotalCost: 8879809,
flexMaxTotalNPV: 7026931,
tradMaxSeatYear: 12979,
tradMaxTotalCost: 6684694,
tradMaxTotalNPV: 5504844,
}
Run Code Online (Sandbox Code Playgroud)
我有一个函数来将这些对象值格式化为字符串,它将输出如下内容:
const maxValues = {
flexMaxSeatYear: '16270',
flexMaxTotalCost: '8879809',
flexMaxTotalNPV: '7026931',
tradMaxSeatYear: '12979',
tradMaxTotalCost: '6684694',
tradMaxTotalNPV: '5504844',
}
Run Code Online (Sandbox Code Playgroud)
我试过的
我可以将这些数字格式化为:
Object.values(maxValues).map(values => values.toLocaleString('en')
// ['16270', '8879809', '7026931' ....]
Run Code Online (Sandbox Code Playgroud)
但这只返回一个只包含值的数组.有没有一种方法可以帮助返回已调整值但带有键的对象?谢谢.
我有一个 api 返回这样的数据集:
const data = {
session: ....,
timestamp: ....,
samples: [
{
key: 'I',
values: [
{ timing: '12356timingdatething', reading: -37.1234 },
{ timing: '12356timingdatething', reading: -32.1234 },
{ timing: '12356timingdatething', reading: 1.1234 },
// ....
],
},
{
key: 'I',
values: [
{ timing: '12356timingdatething', reading: -100.1234 },
{ timing: '12356timingdatething', reading: 5.1234 },
{ timing: '12356timingdatething', reading: 5.3334 },
// ....
],
},
{
key: 'I',
values: [
{ timing: '12356timingdatething', reading: -37.1234 },
{ timing: …Run Code Online (Sandbox Code Playgroud)