我变得如此接近......加载元素很好除了reCaptcha脚本工作方式的事实使得它在创建'g-recaptcha'类的实例时不会完成渲染.所以.如果我使用reCaptcha将加载(每次/功能正确)...
// the div that contains the reCaptcha is in < Contact / >
ReactDOM.render( < Contact / > , document.getElementById('non-header'));
// adding another recaptcha/api.js to the head
var imported = document.createElement('script');
imported.src = 'https://www.google.com/recaptcha/api.js';
document.head.appendChild(imported);
Run Code Online (Sandbox Code Playgroud)
这显然是一个可怕的解决方案,因为每次加载"联系人"时,另一个脚本会附加到头部.不仅如此......我已经在初始文档中放入了一个reCaptcha脚本(这只是一遍又一遍地重新煽动它).使用库API并重置reCaptcha不起作用(见下文)......
ReactDOM.render( < Contact / > , document.getElementById('non-header'));
//var imported = document.createElement('script');
//imported.src = 'https://www.google.com/recaptcha/api.js';
//document.head.appendChild(imported);
grecaptcha.reset();
74:2 error 'grecaptcha' is not defined no-undef !!!
Run Code Online (Sandbox Code Playgroud)
所以我需要在React中访问reCaptcha div的脚本方法.Contact.js是一个非常基本的React组件.它可能只是......
import React, { Component } from 'react';
import './css/Contact.css';
class Contact extends Component {
render() {
return …
Run Code Online (Sandbox Code Playgroud) 这是基本思路...
constructor(props) {
super(props);
this.state = {
children: [{id:1},{id:2}], // HERE ARE THE TWO OBJECTS
style: {top: 0}
};
}
Run Code Online (Sandbox Code Playgroud)
现在说我更新了这两个对象之一,但是这些对象被映射到组件数组。
<div className="thread">
{this.state.children.map((child) =>
<Post
key={child.id}
id={child.id}
/>
)}
</div>
Run Code Online (Sandbox Code Playgroud)
现在...当我更新这些对象之一时...
changeID (id, newID) { // this is a different function, just an example
let temp = this.state.children;
for (let i = 0; i < temp.length; i++) {
if (temp[i].id === id) {
temp[i].id = newID; // <- update this
}
}
this.setState({
children: temp // <- plug temp[] …
Run Code Online (Sandbox Code Playgroud) 我正在尝试做这样的查询......
INSERT INTO article_keyword (article_id, keyword_id, strength)
SELECT ?, keyword.keyword_id, strength_table.strength FROM keyword
INNER JOIN (SELECT 5 AS strength, 'keyword1' AS keyword) AS strength_table
ON strength_table.keyword=keyword.keyword
WHERE keyword IN ('keyword1', 'keyword2', 'keyword3');
Run Code Online (Sandbox Code Playgroud)
在INNER JOIN
上面...我需要SELECT
从 PHP 中的一个数组,看起来像...$array = ['keyword1' => 9, 'keyword2' => 11, 'keyword4' => 13];
其中值是强度,键是关键字。本质上...我想要INNER JOIN
一个带有字段keyword
并strength
基于该数组的临时/动态表。我不需要 PHP/PDO 方面的帮助,但我如何在那里放置表格?有没有一种简单的方法可以生成我可以使用的表格SELECT
?
执行的 SQL 有效...它将一行插入到article_keyword:中('some article id', 5, 'keyword1 id')
。
TL;DR:我可以更改(SELECT 5 AS strength, 'keyword1' AS …
显然,存储更改历史的数组需要大量内存......这就是我的应用程序工作的方式,但似乎有一种更聪明的方法可以做到这一点。
ArrayList<Photo> photoHistory = new ArrayList<>();
photoHistory.add(originalPhoto);
photoHistory.add(change1);
photoHistory.add(change2);
// bad implementation - lots of memory
Run Code Online (Sandbox Code Playgroud)
也许只存储一个原始的和当前的视图模型并保留所使用的方法/过滤器的日志?然后当用户点击“撤消”时,它会取所做的更改总数并再次运行所有更改减去一?这似乎也非常低效。
我想我只是在寻找有关如何实现软件应用程序的一般“撤消”功能的建议。
包.json
"name": "debate",
"homepage": "/debate", // I THINK THIS IS THE PROBLEM
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-router-dom": "^4.1.1"
}
Run Code Online (Sandbox Code Playgroud)
应用程序.js
<BrowserRouter>
<div>
<Route path='/thread/:pathParam?' component={Thread}/>
<Route path='/post' component={Post}/>
</div>
</BrowserRouter>
Run Code Online (Sandbox Code Playgroud)
当我在... [ http://localhost:3000/thread ]上测试应用程序时,一切正常。
当我构建用于生产的应用程序并将我的文件上传到我的服务器时,目录 [ http://www.example.com/debate/thread ] 给出了 404 错误,指出“请求的 URL /debate/thread/ 未在这个服务器。”
The requested URL /debate/thread/ was not found on this server.
Run Code Online (Sandbox Code Playgroud)
[ http://www.example.com/debate/ ] 仍然运行良好。
我不知道如何让 react-router-dom 认识到我们实际上是在一个子目录中......