我正在尝试过滤包含一堆网址的数组.我需要返回仅包含"联系人"一词的网址.
例如,有一个链接 https://www.example.com/v1/contact-us/ca
这应该从过滤器返回.
我试过这个:
const regex = new RegExp("/\bcontact\b", 'g' )
sites.links.filter((val) => {
console.log(regex.test(val.href))
})
Run Code Online (Sandbox Code Playgroud)
它当前只是通过所有域发回false,当我知道有一个域包含单词"contact"时.
我有一个快速服务器,它使用本地json文件作为数据库.我正在使用https://github.com/typicode/lowdb获取getter和setter.
目前,服务器保持启动和重新启动没有任何问题,但无法访问它.下面是我的Server.js文件:
import express from 'express'
import session from 'express-session'
import bodyParser from 'body-parser'
import promisify from 'es6-promisify'
import cors from 'cors'
import low from 'lowdb'
import fileAsync from 'lowdb/lib/storages/file-async'
import defaultdb from './models/Pages'
import routes from './routes/index.js'
const app = express();
const db = low('./core/db/index.json', { storage: fileAsync })
app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/', routes);
app.set('port', process.env.PORT || 1337);
db.defaults(defaultdb).write().then(() => {
const server = app.listen(app.get('port'), () => {
console.log(`Express running ? PORT ${server.address().port}`);
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照本教程创建一个静态站点http://jxnblk.com/writing/posts/static-site-generation-with-react-and-webpack/
我目前收到此错误:ReferenceError中的错误:文档未定义
这是我的app.jsx文件:
import React from 'react';
import ReactDOM from 'react-dom';
import { Router } from 'react-router';
import routes from './config/routes';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
}
}
render() {
return (
<Router>{routes}</Router>
);
}
}
export default App;
module.exports = function render(locals, callback) {
var html = React.renderToStaticMarkup(React.createElement(App, locals))
callback(null, '<!DOCTYPE html>' + html)
}
Run Code Online (Sandbox Code Playgroud)
路线:
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import Layout from '../components/layout';
import …Run Code Online (Sandbox Code Playgroud) 我正在尝试让ScrollMagic使用ES2015导入和React.我收到这个错误:
ERROR in ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js
Module not found: Error: Cannot resolve module 'TimelineMax' in /Users/dillonraphael/Desktop/marbleshark_landingpage/node_modules/scrollmagic/scrollmagic/uncompressed/plugins
@ ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js 31:2-61
Run Code Online (Sandbox Code Playgroud)
这就是我导入所有内容的方式.
import {gsap, TimelineMax, TweenMax} from 'gsap';
import ScrollMagic from 'ScrollMagic';
require('scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap');
Run Code Online (Sandbox Code Playgroud) 我有一个应该呈现随机颜色的功能,但不重复颜色.
意思是如果随机选择蓝色,则无法再次选择.当然,这意味着需要一个默认值.我在考虑使用一个switch声明.
这是我目前的代码:
const colors = {
grey: '#BDC8D1',
blue: '#0500FF',
pink: '#FF00C7',
orange: '#FF7A00'
}
const randomColor = () => {
let keys = Object.keys(colors)
return colors[keys[keys.length * Math.random() << 0]]
}
Run Code Online (Sandbox Code Playgroud) 所以我有如下数据:
[
{
"id": 0,
"title": "happy dayys",
"owner": {"id": "1", "username": "dillonraphael"},
"tags": [{"value": "Art", "label": "Art"}],
"items": []
},
{
"id": 1,
"title": "happy dayys",
"owner": {"id": "1", "username": "dillonraphael"},
"tags": [{"value": "Architecture", "label": "Architecture"}],
"items": []
},
]
Run Code Online (Sandbox Code Playgroud)
我正在尝试过滤数组,并且仅在标签数组包含==指向另一个字符串的值时才返回。
这是我想出的,但似乎仍在发回整个阵列:
const tagMoodboards = _moodboards.filter(mb => { return mb.tags.filter(t => t.value == name) })
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用bootstraps折叠功能来处理rails中的循环.目前只有循环中的第一个项目有效,但是当单击第二个项目时,它只会折叠第一个项目.以下是我的代码.什么是使这种动态变得更好的最佳方法?
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
<h3><%= i.firstname %><%= i.lastname %></h3>
</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
<%= i.email %></br>
Payed: <%= i.payed? %></br>
Birthday: <%= i.dateofbirth %><br />
Address: <%= i.address %><br />
City: <%= i.city %><br />
Province: <%= i.province %><br />
Phone Number: <%= i.phonenumber %><br />
Service Provider: <%= i.serviceprovider %><br />
Gender: <%= i.gender %><br />
Languages: <%= i.languages %><br />
<h3>School Information</h3>
Highschool: <%= …Run Code Online (Sandbox Code Playgroud) 当您单击render方法内的锚标记时,我正在尝试更新组件状态。我已经尝试在构造函数内部进行绑定,但是仍未调用console.log。下面是我的代码。请帮忙。这阻碍了我前进。
这是基于我之前关于stackoverflow的问题而修改的代码。
const React = require('react');
class Navbar extends React.Component {
constructor(...props) {
super(...props);
this.setActiveTab = this.setActiveTab.bind(this)
this.state = {
currentPage: "/"
}
}
setActiveTab(e) {
console.log(e.target)
this.setState({
currentPage: e.target.href
})
}
render() {
const { path } = this.props
let classString = path === this.state.currentPage ? 'nav-item is-tab is-active' : 'nav-item is-tab'
return (
<nav className="nav">
<div className="nav-left">
<a className="nav-item">
<h1>CREATORS NEVER DIE</h1>
</a>
</div>
<div className="nav-right nav-menu">
<a href="/" className={classString} onClick={this.setActiveTab}>
Home
</a>
</div>
</nav>
)
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个接受来自另一个模型的嵌套属性的表单。但是在控制器的新函数中,我正在运行 @item.item_type.build 并收到此错误
undefined method `build' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
这是 items_controller 中的新功能
def new
@item = Item.new
@item_gallery = @item.item_galleries.build
@item_type = @item.item_type.build
end
Run Code Online (Sandbox Code Playgroud)
参数:
def item_params
params.require(:item).permit(:title, :price, :description, item_galleries_attributes: [:id, :item_id, :image], item_type_attributes: [:id, :type, :item_id])
end
Run Code Online (Sandbox Code Playgroud)
在 item.rb(模型)文件中:
has_many :item_galleries, dependent: :destroy
has_one :item_type
accepts_nested_attributes_for :item_galleries
accepts_nested_attributes_for :item_type
Run Code Online (Sandbox Code Playgroud)
我基本上是在尝试从表单下拉列表中设置项目类型。
例子:
<%= f.fields_for :item_types do |t| %>
<%= t.label :type %>
<%= t.select :type, options_for_select(["Type1", "Type2", "Type3"]), prompt: "Select One" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这个想法是最终根据 item_type 过滤项目
javascript ×6
node.js ×3
reactjs ×3
ecmascript-6 ×2
webpack ×2
arrays ×1
css ×1
express ×1
regex ×1