我有.tag
一个以点击/ mousedown操作命名的几个类,我想要更改clear:both
为clear:none
所有.tag
项目.或者将类添加.clearNone { clear:none; }
到所有标记中.
到目前为止我没有运气的尝试:
function mouseDown(e) {
window.addEventListener('mousemove', sizePanel, true);
// Using ID works
var tagsCol = document.getElementById("tags-col");
tagsCol.classList.add("width100");
// Using class does not
var tag = document.getElementsByClassName("tag");
tag.classList.add("clearNone");
};
Run Code Online (Sandbox Code Playgroud)
CSS
.tag {
overflow: hidden;
float: left;
position: relative;
margin: 0 10px 10px 0;
padding: 5px 10px;
width: auto;
cursor: pointer;
clear: both;
@include rounded(4px);
}
.clearNone { clear: none; }
Run Code Online (Sandbox Code Playgroud)
你会怎么做到这一点?注意,有上百.tag
的
显然tagObjects
是一个数组,长度为0
.但是它仍然经过检查并导致错误.
TypeError:无法读取未定义的属性"length"
if (tagObjects != "empty" || tagObjects.length === 0) {
for (var i = 0; i < tagObjects.tags.length; i++) {
temp_tags.push(tagObjects[i].tags);
}
temp_tags.forEach(function(obj) {
if (obj.selected) {
if (vs.tags[map[obj.term]] != undefined) {
vs.tags[map[obj.term]].selected = true;
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
它甚至超过了字符串检查!
我创建了一个生成并返回对象的函数:
function TickersObj(tag, array, boolLots, boolOptions, boolDisplay) {
tag = tag || {};
array = array || [];
boolLots = boolLots || false;
boolOptions = boolOptions || false;
boolDisplay = boolDisplay || true;
console.log('tag = ', tag);
console.log('array = ', array);
console.log('boolLots = ', boolLots);
console.log('boolOptions = ', boolOptions);
console.log('boolDisplay = ', boolDisplay);
this.assoTikArray = array;
this.lotsOfTags = boolLots;
this.tagOptions = boolOptions;
this.tagsHoverDisplay = boolDisplay;
return this;
}
Run Code Online (Sandbox Code Playgroud)
稍后在我的代码中我传递的值如下:
switch(type) {
case 'tagsPanel':
tag.tickers = data.data.ticker_tag.tickers;
var tickersObj = TickersObj(tag, …
Run Code Online (Sandbox Code Playgroud) http://codepen.io/leongaban/pen/xwwdXr?editors=101
我有一个返回Object的API,如下所示:
{ unsure: 5, products: 25, trend: 124 }
我需要做的是获取这些键/值对并将它们添加到数组中,以便它们如下所示:
catArray = [
{ unsure: 5 },
{ products: 5 },
{ trend: 5 },
]
Run Code Online (Sandbox Code Playgroud)
更好的是:
catArray = [
{
name: unsure,
count: 5
},
{
name: products,
count: 15
},
{
name: trend,
count: 50
}
]
Run Code Online (Sandbox Code Playgroud)
当前的代码集代码:
var categories = { unsure: 5, products: 25, trend: 124 }
var catArray = [];
for (var i in categories) {
console.log(i + ":" + categories[i]);
catArray[i] = categories[i]; …
Run Code Online (Sandbox Code Playgroud) 基本上,我想知道在用户点击时在两个img或div之间切换的最佳方法.因此,首先播放图像是可见的,当用户点击时,隐藏播放图像并显示暂停图像.当用户点击暂停图像时,隐藏暂停图像并显示播放图像.
我尝试使用ng-show但我只能弄清楚如何显示两个图像而不隐藏另一个.因此,播放图像将在暂停图像旁边,这是不理想的.
提前致谢 :)
我试过的代码不起作用:
HTML
<button ng-click="changeStatus" ng-show="checkStatus">Play</button>
<button ng-click="changeStatusAgain" ng-hide="checkStatus">Pause</button>
Run Code Online (Sandbox Code Playgroud)
控制器:
$scope.changeStatus=function(){
$scope.checkStatus = false;
}
$scope.changeStatusAgain=function(){
$scope.checkStatus = true;
}
Run Code Online (Sandbox Code Playgroud)
在我的index.js中,addCoin
操作正在运行.
import { addCoin } from './reducer/portfolio/actions'
const element = document.getElementById('coinhover');
const store = createStore(reducer, compose(
applyMiddleware(thunk),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
));
store.dispatch(addCoin('bitcoin'));
Run Code Online (Sandbox Code Playgroud)
在store.dispatch
调用时,我可以在这里看到更新的状态.
但是,我不想从我的index.js调用调度操作,而是从我的组件中调用.
import React from 'react'
import { connect } from 'react-redux'
import * as R from 'ramda'
import * as api from '../../services/api'
import { addToPortfolio, findCoins } from '../../services/coinFactory'
import { addCoin } from '../../reducer/portfolio/actions'
const mapDispatchToProps = (dispatch) => ({
selectCoin(coin) {
return () => {
dispatch(addCoin(coin))
} …
Run Code Online (Sandbox Code Playgroud) 所以刚刚学会了componentWillReceiveProps
已弃用,我们现在需要使用getDerivedStateFromProps
生命周期方法.
https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops
我在下面使用它:
class Main extends Component {
static getDerivedStateFromProps(props) {
console.log('getDerivedStateFromProps', props);
const { modal } = props;
this.setState({ modal });
}
constructor(props) {
super(props);
this.state = {
modal: {}
};
}
Run Code Online (Sandbox Code Playgroud)
但是它出错了 setState
main.js:30未捕获的TypeError:无法在getDerivedStateFromProps(main.js:30)读取null的属性'setState'
我在这里错过了什么?
在我的 React/NextJS 应用程序中,我有这个简单的输入:
成分:
搜索 > 搜索选择 > ExchangeInfo.tsx:
搜索.tsx
<SearchSelect
assets={assets}
selected={selected}
exchange={exchange}
exchanges={exchanges}
fetching={fetching}
aggregate={aggregate}
checkAggregate={this.handleCheckAggregate}
enterPosition={this.handleEnterPosition}
exchangeSelect={this.handleExchangeSelect}
/>
//... the function:
@bind
handleEnterPosition(position: number) {
this.setState({ position })
}
Run Code Online (Sandbox Code Playgroud)
搜索选择
<SearchExchanges
selected={selected}
exchange={exchange}
exchanges={exchanges}
checkAggregate={checkAggregate}
aggregate={aggregate}
enterPosition={this.props.enterPosition}
exchangeSelect={this.props.exchangeSelect}
/>
Run Code Online (Sandbox Code Playgroud)
交换信息
import React from 'react'
import { bind } from 'decko'
import { IAsset, IMarketAsset } from '../../shared/types'
import { EnterPositionStyle } from '../../styles'
interface IPropsInfo {
asset: IAsset
}
interface IPropsCount {
exchanges: IMarketAsset[]
}
interface IPropsPosition …
Run Code Online (Sandbox Code Playgroud) 我有从 redux 中提取的事件,如果events
数组包含数据,updateData
则将用于将事件过滤到状态 var 中data
。
我已经data
和events
都添加到了这里提到的依赖数组中。但我仍然收到此错误:
const SingleTable = () => {
const events = useSelector(state => eventsSelector(state));
const [data, updateData] = useState([]);
const [sortCol, updateSortCol] = useState(0);
const [sortDir, updateSortDir] = useState('ascending');
useEffect(() => {
const formattedArray = events ? formatLoss(events): [];
events && updateData(formattedArray);
}, [data, events]);
//...
Run Code Online (Sandbox Code Playgroud)
想法,想法?
在我的组件中,我有一个名为 AuthForm 的函数,它使用一个开关来渲染 3 个组件中的 1 个。在方法参数中,我传入了一个类方法数组。除了如何正确键入类方法本身之外,我已经记录了所有类型。
错误:
(别名)接口 ISignInData
导入ISignInData
声明类型既不是“void”也不是“any”的函数必须返回一个值。ts(2355)
export interface ISignInData {
email: string
password: string
}
export interface IAccountData {
email: string
password: string
password2: string
}
export interface IForgotData {
email: string
}
export type TSignIn = (email: string, password: string) => (ISignInData)
export type TCreateAccount = (email: string, password: string, password2: string) => (IAccountData)
export type TForgot = (email: string) => (IForgotData)
Run Code Online (Sandbox Code Playgroud)
import React from 'react'
import { Astronaut, Login, Create, …
Run Code Online (Sandbox Code Playgroud) http://jsfiddle.net/leongaban/BvuT5/
试图让第二个警报弹出两次,但似乎for循环甚至没有运行.
jQuery的
var wireRequestorCard = function(jarjar) {
alert('1st alert');
var loop_num = 0;
for (var i = 0, length = jarjar.length; i < length; i++) {
loop_num = i;
alert('Where is this Alert? '+i);
}
alert('Closing Alert');
}
var jarjar = 2;
wireRequestorCard(jarjar);
Run Code Online (Sandbox Code Playgroud) 我试图在金字塔中获得以下数组的长度.
当我在下面尝试这个
${outbox_details.details['declined']}
${outbox_details.details['accepted']}
${outbox_details.details['pending']}
Run Code Online (Sandbox Code Playgroud)
我看到我认为在HTML中生成的空数组:
上面的完整标记:
<li>
<img src="..." alt="Denied"/>${outbox_details.details['declined']} denied
</li>
<li>
<img src="..." alt="Accepted"/>${outbox_details.details['accepted']} accepted
</li>
<li>
<img src="..." alt="Pending"/>${outbox_details.details['pending']} pending
</li>
Run Code Online (Sandbox Code Playgroud)
我试过.length和.len,但是他们都在PyCharm中出错了:
${outbox_details.details.length.(['declined'])}
${outbox_details.details.len['declined']}
${outbox_details.details.len(['declined'])}
Run Code Online (Sandbox Code Playgroud)
如果您是Python或后端开发人员,您将如何获得已接受,已拒绝或待定数组的长度?
javascript ×10
reactjs ×5
arrays ×3
object ×2
angularjs ×1
css ×1
for-loop ×1
if-statement ×1
input ×1
ios ×1
jquery ×1
loops ×1
pyramid ×1
python ×1
react-hooks ×1
react-redux ×1
redux ×1
typescript ×1
use-effect ×1
use-state ×1