我在App.js中有以下内容.出于调试目的,我可以console.log
使用当前状态store.getState()
.
const App = () => {
const store = createStore(reducers);
console.log(store.getState());
return (
<Provider store={store}>
<Router />
</Provider>
);
};
export default App;
Run Code Online (Sandbox Code Playgroud)
现在我如何store.getState()
从这个应用程序中的容器中控制console.log .
更新:在注释中的"连接"建议之后,这是容器中代码的底部:
export default connect(mapStateToProps, {
Decrease,
Increase,
selectNumber
})(TableGenerator);
Run Code Online (Sandbox Code Playgroud)
我在哪里添加getState()
?
如何检查 wp_insert_post 之前的帖子是否存在以避免重复?
如果我删除“if”语句(post_exists())并继续重新插入产生多个重复的帖子,下面的代码就可以工作。我用 post_exists() 编写了 if 语句,只是为了开始实现检查逻辑,但是当我添加 if 语句时,某些东西就会中断,下面的列表甚至不会被打印。
$body = wp_remote_retrieve_body( $request );
$data = json_decode(utf8ize($body), true);
$data_events = $data['events'];
if( ! empty( $data_events ) ) {
echo '<ul>';
foreach( $data_events as $event ) {
// the if statement below seems to break things ie. no li below printed.
if ( post_exists( $event['name'] ) == 0 ) {
echo 'exists';
} else {
echo 'doesnt exist';
}
echo '<li>';
echo $event['id'];
echo '<a href="' . esc_url( $event['uri'] ) …
Run Code Online (Sandbox Code Playgroud) 我创建了许多强力查询。到目前为止,我已经通过合并两个源(合并为新源)来完成它们。现在只想从现有查询中提取。我不需要将它与另一个合并。我想对查询进行一些过滤并将其另存为新查询。当我单击查询并编辑(过滤)它时,它会更新现有的查询。我想将过滤结果保存为新查询。
我正在使用 Excel 2016 (O365)。谢谢
我需要一些帮助来修改我的减速器。我正在使用 Redux Toolkit,并且在其中一个状态切片中我有一个带有一些分组设置的对象:
initialState: {
...
userSettings: {mode: 2, subscription: false, setting3: 'text', setting4: 'another text'},
...
}
Run Code Online (Sandbox Code Playgroud)
我的减速器是:
setUserSettings: (state, action) => {
state.userSettings: action.payload
}
Run Code Online (Sandbox Code Playgroud)
在组件的不同部分,我会更新 userSettings 对象中的各个设置:
dispatch(setUserSettings({ mode: 4 }))
Run Code Online (Sandbox Code Playgroud)
在另一个地方:
dispatch(setUserSettings({ setting3: 'some other text'})
Run Code Online (Sandbox Code Playgroud)
我该如何修改减速器才能做到这一点?谢谢
在for循环中评论为:
//迭代数组并将每个元素追加为li
...如果我只是放入console.log(tags [x]),有一个闭包可以正常工作; 这表明封闭按预期工作.但是,当我把闭包应该包含的实际代码,即.this.displayImg(标签[X]); 它会抛出一个错误.当我点击li时,我得到:
Uncaught TypeError: this.displayImg is not a function
(anonymous function) @ script.js:49
Run Code Online (Sandbox Code Playgroud)
请告知我如何从那个地方访问this.displayImg.
var myGallery = (function () {
var s;
return {
settings: {
data: JSON.parse(data),
filter: document.getElementById("filter"),
gallery: document.getElementById("gallery")
},
init: function () {
// kick things off
s = this.settings;
// By default, call the fillImages function with 'all' tag
this.createFilters("all");
},
createFilters: function (tag) {
// Load the image data
// I made imgs global as I couldn't access it from …
Run Code Online (Sandbox Code Playgroud) 我正在阅读关于Mozilla开发者网站上的闭包的解释,并且我正在苦苦挣扎.请查看Mozilla网站上的以下代码.我有点理解它是如何工作的,但我认为我的评论下面的代码也应该有效.如果点击18和20,为什么它不起作用?
/* mozilla dev code */
function makeSizer(size) {
return function() {
document.body.style.fontSize = size + 'px';
};
}
var size12 = makeSizer(12);
var size14 = makeSizer(14);
var size16 = makeSizer(16);
document.getElementById('size-12').onclick = size12;
document.getElementById('size-14').onclick = size14;
document.getElementById('size-16').onclick = size16;
/* end of mozilla dev example */
/* my code starts */
/* see - no inner function below */
function makeS(size) {
document.body.style.fontSize = size + 'px'
}
/* Let's see if that works */
var size18 = makeS(18); …
Run Code Online (Sandbox Code Playgroud) 数组以[]开头,然后随着数字的添加而不断增长.
我正在尝试创建一个选择器来提取数组的最后2个元素.
我有以下内容:
const getHistory = (state) => state.score.history;
export const lastTwo = createSelector(
[getHistory],
history => (history.length > 1 ? history.slice(-1, -3) : 0)
);
Run Code Online (Sandbox Code Playgroud)
它显示初始值0但是它不输出任何值.请指教.如果,仅出于测试目的,我做:
export const lastTwo = createSelector(
[getHistory],
history => history
);
Run Code Online (Sandbox Code Playgroud)
它在添加时正确输出数组元素.
编辑:
根据以下答案,答案是:
export const lastTwo = createSelector(
[getHistory],
history => history.slice(-2)
);
Run Code Online (Sandbox Code Playgroud) 我应该在哪里添加我在 Understrap (WP) 中的自定义 js 文件?
js/
或者
源代码/js/
另外,我假设我需要从 inc/enqueue.php 加载它并修改 gulpfile.js 来编译它。
这样对吗?
我打开了 Gutenberg 并试图在页面上创建一个短代码。这是我在functions.php中的代码
// Enable shortcodes in text areas
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
// Enable shortcodes
add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');
function first_shortcode() {
$content = '<h1>This is my first shortcode</h1>';
return $content;
}
add_action('my_shortcode','first_shortcode');
Run Code Online (Sandbox Code Playgroud)
在帖子中,我将 [my_shortcode] 放在了短代码部分,如下所示:
但是当我显示页面时,它只是呈现 [my_shortcode]。我正在运行 Wordpress 4.9.8
谢谢
谷歌搜索我找到了一个程序来突出显示活动工作表中的合并单元格:
Sub DeleteRows()
Dim x As Range
For Each x In ActiveSheet.UsedRange
If x.MergeCells Then
x.Interior.ColorIndex = 8
ActiveCell.EntireRow.Delete
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
所以我添加了ActiveCell.EntireRow.Delete
语句来删除当前迭代的行.
我哪里错了?
我并不关心突出显示合并的单元格.最终目标是删除其中包含合并单元格的任何行.
我找不到对以下语法的任何引用:
data?.length > 0 && ...rest of the code
Run Code Online (Sandbox Code Playgroud)
我理解双&符号和其余的。我唯一不清楚的是“数据”变量后面的问号。它是什么意思或叫什么?我找不到任何相关信息。
通常,我会使用以下内容检查变量是否存在(为真):
data && if_data_is_true_execute_this
Run Code Online (Sandbox Code Playgroud) javascript ×4
wordpress ×3
excel ×2
redux ×2
arrays ×1
closures ×1
object ×1
php ×1
powerquery ×1
react-redux ×1
reselect ×1
shortcode ×1
vba ×1