我有这种格式的文件:
coupait ||| eastern ||| 0.045454545454545456 2.718 ||| 0-0 |||
instaurer ||| characteristic ||| 5.797101449275362E-4 2.718 ||| 0-0 |||
tiendrait ||| fails ||| 0.005 2.718 ||| 0-0 |||
Run Code Online (Sandbox Code Playgroud)
我想搜索保存在两个变量中并由|||分隔的一对单词。我徒劳地尝试了许多替代方法,例如:
grep "$word1 ||| $word2 |||" $file
Run Code Online (Sandbox Code Playgroud)
我试图这样转义管道字符:
grep '$word1 \|\|\| $word2 \|\|\|' $file
Run Code Online (Sandbox Code Playgroud)
如何匹配文件中的管道?
我有简单的react/redux app和带有两个目标自动选择组件的搜索表单容器:
class QuoteBox extends Component {
onSelectSuggest(target, destination) {
this.props.setDestination(destination, target);
}
render() {
return (
<Destination
direction="From"
key="dest-from"
enterText={this.props.enterText.bind(this)}
onSelectSuggest={this.onSelectSuggest.bind(this, "origin")}
dataSource={this.props.originSuggests} />
<Destination
direction="To"
key="dest-to"
enterText={this.props.enterText.bind(this)}
onSelectSuggest={this.onSelectSuggest.bind(this, "destination")}
dataSource={this.props.destinationSuggests} />
)
}
}
function mapStateToProps(state) {
return {
originSuggests: state.originSuggests,
destinationSuggests: state.destinationSuggests,
origin: state.origin,
destination: state.destination
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({
enterText: enterText,
setDestination: setDestination
}, dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps )(QuoteBox)
Run Code Online (Sandbox Code Playgroud)
和Destination是一个简单的组件
export default class Destination extends Component {
render() {
return ( …Run Code Online (Sandbox Code Playgroud) 我最近开始学习React/Redux,现在我正在尝试构建一个小的单页面应用程序.
最近我遇到了一个我不理解但无法修复的问题.
我来告诉你代码:
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
import App from './components/App'
import Home from './components/Home'
import About from './components/About'
const reducer = (state = {}, action) => {
return state
}
const store = createStore(
combineReducers({
reducer,
routing: routerReducer
})
)
const history = syncHistoryWithStore(hashHistory, store) …Run Code Online (Sandbox Code Playgroud) 看起来很简单的问题。我尝试了很多理解但失败了。
据我所知,Hibernate 一级缓存意味着会话级缓存。当我们在同一个会话中多次检索同一个对象时,它将从缓存中检索。
例如,我在数据库中有一个 ID 为 100 的员工记录。
我打开一个会话并获取该员工对象。直到我关闭会话该对象在同一会话中可用。
问题:为什么我需要在同一个会话中多次检索同一个对象(在我关闭它之前它在会话中是如何可用的)?
我使用lodash从特定键创建一个对象数组,然后从其对象中删除此给定键.
我有这个
var cars = [{
"itemID": "-KUsw42xU-S1qA-y3TiI", // use this as key
"name": "Car One",
"qtd": "1"
},
{
"itemID": "-KUsw42xU-r1qA-s3TbI",
"name": "Car Two",
"qtd": "2"
}
]
Run Code Online (Sandbox Code Playgroud)
试图得到这个:
var cars = {
"-KUsw42xU-S1qA-y3TiI": {
"name": "Car One",
"qtd": "1"
},
"-KUsw42xU-r1qA-s3TbI": {
"name": "Car Two",
"qtd": "1"
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过这种方法,但我没有成功.
_.chain(a)
.keyBy('itemID')
.omit(['itemID'])
.value();
Run Code Online (Sandbox Code Playgroud) 我是新手在反应和终极版.
问题:在redux中实现"datasource"(类似于kendo-ui 数据源)的最佳方法是什么?
我试图将我的所有小部件数据源存储在一个地方(我创建了数据源简化器)并将数据源"绑定"到它的小部件(如表小部件,列表视图,组合框等).数据源必须拥有自己的api(如addFilter,addSort,getFiltered等),并且还存储应用的过滤器和数据.
我想将所有数据源存储在redux存储中(这就是为什么我需要创建数据源并在创建窗口小部件之前调度它的创建).
问题是当我创建react-redux连接器到我的"智能"小部件的容器组件时,我需要使用props发送我的数据源,但此时不创建数据源.
如果我发送虚拟初始数据源(没有调度它的创建和数据填充)然后调度它并在componentDidMount上填充数据 - 我的小部件的渲染函数被调用两次
我想我需要某种"包装"功能,但现在我不知道该怎么做.
也许有一些如何实现"数据源功能"的例子?
我需要一个正则表达式来匹配以下内容:
在每个字符串的6个字符后面有一个
';'
例子:
aaaaaa;z5z5z5;zdzzzt; (有效)
aaadzdaaa;z5z5dzdzz5;zdzdzd; (无效)
我试过了:
(([A-Za-z0-9]{6};$))
Run Code Online (Sandbox Code Playgroud)
但它只根据最后的顺序进行验证.
我正在研究一些代码问题,我来到这个'去除噪音的事情',我想重点是逃避反斜杠\并使用替换方法,这很容易.但我不想使用替换,而是发现自己在尝试使用拼接方法删除项目时遇到了麻烦.
有趣的是,当我在Chrome开发工具中调试时,我一步一步地看到项目被删除,但是console.log吐出某些字符($ /·|ªl)有问题要删除,最后返回并加入那些字符.这是为什么?
function removeNoise(str) {
var base = "%$&/#·@|º\ª";
var arr = str.split('');
for(var i = 0; i < arr.length; i++) {
var item = arr[i];
var condition = base.indexOf(item);
if(condition + 1) {
//works like a charm
//arr[i] = '';
arr.splice(i,1);
//this thing wont work
//when debugging it removes the items from the array
//console log print no removing
}
}
return arr.join('');
}
removeNoise('he%$&/#·@|º\ª\llo'); //=> $/·|ªlloRun Code Online (Sandbox Code Playgroud)
如果我跑
var num = 23;
var n = num.toString();
console.log(n)
Run Code Online (Sandbox Code Playgroud)
它23按预期记录,但如果我toString()直接应用于数字,
var n = 15.toString();
console.log(n)
Run Code Online (Sandbox Code Playgroud)
它会抛出一个错误:
Uncaught SyntaxError: Invalid or unexpected token.
Run Code Online (Sandbox Code Playgroud)
我注意到它也适用于num变量中的十进制值(如.3,.99,2.12,99.1)等.有人可以帮我理解差异以及此函数的工作原理
我想使用正则表达式而不是string.replace()来获取字符串的前6个字符和同一个字符串的最后4个字符,并用另一个字符替换它:&例如.字符串总是带有16个字符.我做了一些研究,但我以前从未使用过正则表达式.谢谢