我真的不知道为什么我不能在课堂上使用getLayoutPosition();或使用getAdapterPosition();方法.
class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private ImageView image;
private TextView title;
private TextView price;
public MyViewHolder(View itemView) {
super(itemView);
image = (ImageView)itemView.findViewById(R.id.horizontal_list_image);
title = (TextView)itemView.findViewById(R.id.horizontal_list_title);
price = (TextView)itemView.findViewById(R.id.horizontal_list_price);
image.setOnClickListener(this);
title.setOnClickListener(this);
price.setOnClickListener(this);
}
public ImageView getImage() {
return image;
}
public TextView getTitle() {
return title;
}
public TextView getPrice() {
return price;
}
@Override
public void onClick(View v) {
Toast.makeText(context, "CLICK", Toast.LENGTH_SHORT).show();
getLayoutPosition(); //no method like that
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用getPosition()但不推荐使用以上方法.文件
可以说我有一个实体:
@Entity
public class Person {
@Id
private int id;
private String name;
private Date birthdate;
}
Run Code Online (Sandbox Code Playgroud)
我想有一种方法将OrderSpecifier根据String参数返回该实体的字段,该参数将是实体字段之一的名称。
/**
* fieldName - name of field from Person entity
*/
private OrderSpecifier<?> getSortedColumn(Order order, String fieldName){
//how to implement this???
}
Run Code Online (Sandbox Code Playgroud) 我有一个代码:
import React from 'react';
import ReactDOM from 'react-dom';
import Navigation from './Navigation';
import PublicPage from './PublicPage';
import LoginPage from './LoginPage';
import SecuredPage from './SecuredPage';
import {Route, Switch, Redirect, BrowserRouter} from 'react-router-dom';
ReactDOM.render(
<BrowserRouter>
<Navigation>
<Switch>
<Redirect from='/' to='/public'/>
<Route path="/public" component={PublicPage}/>
<Route path="/login" component={LoginPage}/>
<Route path="/secured" component={SecuredPage}/>
</Switch>
</Navigation>
</BrowserRouter>,
document.getElementById("react-app")
);
Run Code Online (Sandbox Code Playgroud)
现在我想要路径/重定向到/public路径但不知何故这种配置不起作用.其他路线也会停止渲染.我想我在文档中做了一切
这是我的 webpack.config.js 文件:
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const config = {
entry: {
bundle: './javascript/index.js'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].[chunkhash].js'
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
{
test: /\.(jpe?g|png|gif|svg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 40000
}
},
'image-webpack-loader'
]
}
]
},
plugins: [
new ExtractTextPlugin('style.css'),
new HtmlWebpackPlugin({ …Run Code Online (Sandbox Code Playgroud) 我有 4 个按钮,每个按钮都有名称 id 和选定的布尔标志。
我想要实现的是,在单击按钮时,应该更改该特定按钮的布尔按钮标志。为此,我需要在 map 函数中为该特定按钮 Id 设置状态。
我的问题是我无法在地图函数中为那个特定的点击按钮设置状态,它的 btnSelected 应该改变
我的目标是创建一个多选取消选择按钮。它是用户感兴趣的选择,并基于此反映 UI 以及我的数组。这是我的代码。
感谢期待。
import React, { Component } from "react";
import { Redirect } from "react-router-dom";
export default class Test extends Component {
constructor(props, context) {
super(props, context);
this.handleChange = this.handleChange.bind(this);
this.state = {
value: "",
numbers: [1, 2, 3, 4, 5],
posts: [
{
id: 1,
topic: "Animal",
btnSelected: false
},
{
id: 2,
topic: "Food",
btnSelected: false
},
{
id: 3,
topic: "Planet",
btnSelected: …Run Code Online (Sandbox Code Playgroud) 为什么在使用表单元素时必须将e.arget.name放在方括号中?
这是我的代码:
onChange (e) {
this.setState({ *[e.target.name]* : e.target.value});
}
(...)
<div>
<label htmlFor=""> Title : </label>
<input type="text" name="title" onChange={this.onChange} value={this.state.title} />
</div>
</form>
Run Code Online (Sandbox Code Playgroud) 我有一个反应组件,它在 componentWillMount 中进行 AJAX 调用,并支持接收到的数据以响应 redux 存储。这是代码
componentWillMount() {
var self = this;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
console.log(this.responseText);
var json = JSON.parse(this.responseText);
var data = {
json
};
self.props.dispatch({
type: "ADD_Exams",
data
});
}
};
xmlhttp.open("GET", "http://127.0.0.1:8000/getExams/", true);
xmlhttp.send();
}
Run Code Online (Sandbox Code Playgroud)
在减速器中,我将在操作中接收到的数据分配给减速器状态中定义的数组。
const initialState = {
exams:[]
}
const examreducer = (state = initialState, action) => {
switch (action.type) {
case "ADD_Exams":
return {
...state,
exams: [...state.exams, …Run Code Online (Sandbox Code Playgroud) 我正在学习接口。这里会发生什么?以及为什么我收到一条消息:
“对超级类型SomeInterface2的非法引用,不能绕过更具体的直接超级类型interfejsy.SomeInterface3”
public interface SomeInterface1 {
public default void action(){
System.out.println("default interface1 method");
};
}
public interface SomeInterface2 {
public default void action(){
System.out.println("default interface2 method");
};
}
public interface SomeInterface3 extends SomeInterface2{
public default void action(){
System.out.println("default interface3 method");
}
}
Run Code Online (Sandbox Code Playgroud)
...
public class ClassImplementingInterface implements SomeInterface1, SomeInterface2, SomeInterface3{
//Every interface has action() method so we have to override it
@Override
public void action() {
SomeInterface1.super.action();
SomeInterface2.super.action(); //---- compiler error
SomeInterface3.super.action();
}
}
Run Code Online (Sandbox Code Playgroud) React router Link 似乎不适用于我的应用程序。似乎我失踪了,因为基本不起作用。我的链接组件将 URL 更新为 /products/singleproduct 但我的页面刚刚中断....谁能告诉我如何解决这个问题?
应用程序.js
import React from 'react';
import Header from './Header';
import Body from './Body';
import Main from './Main';
require('../../scss/style.scss');
const App = () => (
<div>
<Header />
<Main />
</div>
);
export default App;Run Code Online (Sandbox Code Playgroud)
主程序
import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';
import ServicePage from './ServicePage';
import ProductPage from './ProductPage';
import SingleProductPage from './SingleProductPage';
import Body from './Body';
export default class Main extends Component { …Run Code Online (Sandbox Code Playgroud)我正在使用 bootstrap 3,这可能是一个愚蠢的问题,但我无法在fa-chart-line此处禁用图标上的悬停效果:
<h5>
<span class="btn btn-circle blue1-icon">
<i class="fas fa-chart-line"></i>
</span> My Title
</h5>
Run Code Online (Sandbox Code Playgroud)
CSS:
.blue1-icon {
background-color: #019993;
color: #fff;
}
.blue1-icon:hover {
text-decoration: none;
}
.btn-circle {
width: 30px;
height: 30px;
text-align: center;
padding: 6px 0;
font-size: 12px;
line-height: 1.428571429;
border-radius: 15px;
}
.btn-circle:hover {
cursor: default;
text-decoration: none !important;
}
.fa-chart-line:hover {
text-decoration: none !important;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
reactjs ×5
javascript ×4
java ×2
react-router ×2
redux ×2
android ×1
css ×1
default ×1
html ×1
interface ×1
jpa ×1
map-function ×1
node.js ×1
object ×1
querydsl ×1
react-redux ×1
redirect ×1
setstate ×1
state ×1
webpack ×1