- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试在 ReactJs 上进行双向绑定(bind)并尝试使用 LinkedStateMixin。根据 React 网站,从 React 0.14 开始,所有插件都已移动到单独的包中:https://facebook.github.io/react/blog/2015/07/03/react-v0.14-beta-1.html所以我通过 npm 安装了 react-addons-linked-state-mixin 但是当我尝试使用它时出现以下错误:
Uncaught TypeError: this.linkState is not a function
我的代码是:
import React, { PropTypes } from 'react';
import TimelineEvent from './TimelineEvent';
import {TimelineEditButton} from './TimelineEvent';
import styles from './Main.css';
import withStyles from '../../../../decorators/withStyles';
import MainView from '../../../MainView';
import SwapBlock from '../../../SwapBlock';
import RoundButton from '../../../RoundButton';
import LightBox from '../../../LightBox';
import Dropzone from 'react-dropzone';
import classnames from 'classnames';
import LinkedStateMixin from 'react-addons-linked-state-mixin';
@withStyles(styles)
class Main extends React.Component {
render() {
let session = this.props.session
let user = this.props.user
return (
<MainView>
<Timeline session={session} user={user} />
</MainView>
);
}
}
class Timeline extends React.Component {
// Hide all Partials
constructor() {
super();
this.state = {
eventTitle: '',
eventPlace: '',
eventLocation: '',
eventDescription: ''
};
this.state['addEventPartial'] = false;
this.state.files = [];
}
openPartial(tag) {
var tags = {};
tags[tag] = true;
this.setState(tags);
var e = document.getElementById("add-timeline-event");
if (!!e && e.scrollIntoView) {
e.scrollIntoView();
}
}
closePartial(tag) {
var tags = {};
tags[tag] = false;
this.setState(tags);
}
openLightbox(tag) {
var tags = {};
tags[tag] = true;
this.setState(tags);
}
closeLightbox(tag) {
var tags = {};
tags[tag] = false;
this.setState(tags);
}
getPartial(tag)
{
return this.state[tag];
}
getLightbox(tag)
{
return this.state[tag];
}
onDrop(files) {
console.log('Received files: ', files);
this.setState({
files: files
});
}
render() {
let session = this.props.session
let user = this.props.user
let isAuth = session.isAuth
let addEvent = {}
let events = []
let data = [{
id: "123",
key: "1",
type: "academic",
time: "2015 - 2016",
title: " MSc Software Engineering",
place: "University of Oxford",
location: "Oxford, United Kingdom",
description: "Lorem impsum",
gallery: []
},{
id: "234",
key: "2",
type: "professional",
time: "2015 - 2016",
title: " MSc Software Engineering",
place: "University of Oxford",
location: "Oxford, United Kingdom",
description: "Lorem impsum",
gallery: [
{url: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/v/t1.0-1/p160x160/10923196_10204583699694173_6145976884213630323_n.jpg?oh=bd235908314ecf0ab5afa8d3f92f5abf&oe=567B51F9&__gda__=1450897067_285c7c8c720c0f130453b37e9ff9b2f8"}
]
},{
id: "567",
key: "3",
type: "misc",
time: "2015 - 2016",
title: " MSc Software Engineering",
place: "University of Oxford",
location: "Oxford, United Kingdom",
description: "Lorem impsum",
gallery: [{
index: 1,
url: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/v/t1.0-1/p160x160/10923196_10204583699694173_6145976884213630323_n.jpg?oh=bd235908314ecf0ab5afa8d3f92f5abf&oe=567B51F9&__gda__=1450897067_285c7c8c720c0f130453b37e9ff9b2f8"
}]
}]
// Loop through all Timeline Events
for (var i = 0; i < data.length; i++) {
let directions;
let gallery = [];
if (i % 2 == 0) {
directions = "direction-r";
} else {
directions = "direction-l"
}
for (var j = 0; j < data[i].gallery.length; j++) {
gallery.push(
<a onClick={this.openLightbox.bind(this, "galleryLightbox")}><img alt={data[i].title} className="TimelineViewGalleryImage" src={data[i].gallery[j].url} /></a>
)}
events.push(
<li>
<TimelineEvent
key = {data[i].id}
type={data[i].type}
time = {data[i].time}
title = {data[i].title}
place = {data[i].place}
location = {data[i].location}
description = {data[i].description}
direction = {directions}
session = {session}
user = {user}>
{gallery}
<TimelineEditButton deleteClick={this.openPartial.bind(this, "addEventPartial")}
editClick={this.openPartial.bind(this, "addEventPartial")}
session={session} user={user} eventId={data[i].id} />
</TimelineEvent>
</li>
)
}
// Add Event to timeline Dialog
if (isAuth){
addEvent = (
<form className="AddEventForm">
<SwapBlock show={!this.getPartial("addEventPartial")}>
<div className="AddEventButton">
<RoundButton onClick={this.openPartial.bind(this, "addEventPartial")} color="green">
<span className="EventPlus">+</span>
</RoundButton>
</div>
</SwapBlock>
<SwapBlock show={this.getPartial("addEventPartial")}>
<div className="TimelineBackdrop"></div>
<div className="AddTimelineEvent">
<button className="AddTimelineEventCloseButton" onClick={this.closePartial.bind(this, "addEventPartial")}>
<i className="fa fa-times"></i>
</button>
<h3>Add Event</h3>
<div className="AddEventTitle TimelineFormField">
<input value={eventTitle} className="TimelineInput" placeholder="Title" />
</div>
<div className="AddEventPlace TimelineFormField">
<input valueLink={this.linkState('eventPlace')} className="TimelineInput" placeholder="Place" />
</div>
<div className="AddEventLocation TimelineFormField">
<input valueLink={this.linkState('eventLocation')} className="TimelineInput" placeholder="Location" />
</div>
<div className="AddEventDescription TimelineFormField">
<textarea valueLink={this.linkState('eventDescription')} rows="2" className="TimelineInput" placeholder="Description"></textarea>
</div>
<StartDateSelect />
<EndDateSelect />
<EventTypeSelect />
<div className="AddEventMedia TimelineFormField">
<Dropzone className="Dropzone" activeClassName="DropzoneActive" ref="dropzone" multiple={true} disableClick={false} onDrop={this.onDrop.bind(this)}>
<div>Try dropping some files here, or click to select files to upload.</div>
{this.state.files.length > 0 ?
<div>
<div>{this.state.files.map((file) =>
<div className="DropzoneUploadedImageContainer">
<img className="DropzoneUploadedImage" src={file.preview} />
<br className="clear" />
</div> )}
</div>
<p className="DropzoneFileCount">{this.state.files.length} files</p>
</div> : null}
</Dropzone>
<p className="AddTimelineEventNote">Note: Images only, maximum 4 images and maximum file size is 2 MB</p>
<button className="SaveEventButton btn btn-primary">Save</button>
<button onClick={this.closePartial.bind(this, "addEventPartial")} className="SaveEventButton btn btn-default">Cancel</button>
</div>
</div>
</SwapBlock>
<SwapBlock show={this.getPartial("addEventPartial")}>
<div className="TimelineSeparator"></div>
</SwapBlock>
</form>
);
}
// Render Timeline
return (
<div className="Timeline">
<LightBox show={this.getLightbox("galleryLightbox")}>
<button className="TimelineGalleryCloseButton" onClick={this.closeLightbox.bind(this, "galleryLightbox")}>
<i className="fa fa-times"></i>
</button>
<img src="https://d13yacurqjgara.cloudfront.net/users/14268/screenshots/1934662/taptap_1x.png" />
</LightBox>
<h3><span className="TimelineHeading">Timeline</span>
<div className="TimelineNav">
<button href="#" className="allFilter active">All</button>
<button href="#" className="professionalFilter">Professional</button>
<button href="#" className="academicFilter">Academic</button>
<button href="#" className="miscFilter">Miscellaneous</button>
</div>
<br className="clear" />
</h3>
<div className="TimelineContainer" id="add-timeline-event">
{addEvent}
<ul className="TimelineView">
{events}
</ul>
</div>
</div>
);
}
}
class StartDateSelect extends React.Component {
render() {
return(
<div className="AddEventDescription TimelineFormField">
<h5 className="EventTypeField EventDateField"><span className="EventTypeLabel">Start Date</span></h5>
<div className="EventDateContainer">
<select className="TimelineFormField">
<option selected disabled>Year:</option>
<option value="--">--</option>
<option value="01">2015</option>
<option value="02">2014</option>
<option value="03">2013</option>
</select>
<select className="TimelineFormField">
<option selected disabled>Month:</option>
<option value="--">--</option>
<option value="January">December</option>
<option value="February">November</option>
<option value="March">October</option>
</select>
<select className="TimelineFormField">
<option selected disabled>Day:</option>
<option value="--">--</option>
<option value="2014">31</option>
<option value="2015">30</option>
<option value="2016">29</option>
</select>
</div>
<br className="clear" />
</div>
);
}
}
class EndDateSelect extends React.Component {
render() {
return(
<div className="AddEventDescription TimelineFormField">
<h5 className="EventTypeField EventDateField"><span className="EventTypeLabel">End Date</span></h5>
<div className="EventDateContainer">
<select className="TimelineFormField">
<option selected disabled>Year:</option>
<option value="--">--</option>
<option value="01">2015</option>
<option value="02">2014</option>
<option value="03">2013</option>
</select>
<select className="TimelineFormField">
<option selected disabled>Month:</option>
<option value="--">--</option>
<option value="January">December</option>
<option value="February">November</option>
<option value="March">October</option>
</select>
<select className="TimelineFormField">
<option selected disabled>Day:</option>
<option value="--">--</option>
<option value="2014">31</option>
<option value="2015">30</option>
<option value="2016">29</option>
</select>
</div>
<br className="clear" />
</div>
);
}
}
class EventTypeSelect extends React.Component {
render() {
return(
<div className="AddEventDescription TimelineFormField">
<h5 className="EventTypeField"><span className="EventTypeLabel">Event Type</span>
<button className="EventTypeFieldProfessional"><span className="TypeDot"></span>Professional</button>
<button className="EventTypeFieldAcademic"><span className="TypeDot"></span>Academic</button>
<button className="EventTypeFieldMiscellaneous"><span className="TypeDot"></span>Miscellaneous</button>
</h5>
</div>
);
}
}
export default Main;
我不确定我做错了什么。
有什么想法吗?
谢谢
最佳答案
就目前而言,React and ES6 has no support for mixins .
然而,实现双向绑定(bind)非常简单。
class Something extends React.Component {
state = {
email: ''
}
emailValueLink = (value) => {
return {
value: this.state.email,
requestChange: this.handleEmailChange
};
}
handleEmailChange(newEmail) {
this.setState({email: newEmail});
}
render() {
<input type="email" valueLink={this.emailValueLink()} />
}
}
关于javascript - React LinkedStateMixin 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32718287/
问题是,当用户回复彼此的帖子时,我必须这样做: margin-left:40px; 对于 1 级深度 react margin-left:80px; 对于 2 层深等 但是我想让 react div
我试图弄清楚如何将 React Router 与 React VR 连接起来。 首先,我应该使用 react-router dom/native ?目前尚不清楚,因为 React VR 构建在 Rea
我是 React 或一般编码背景的新手。我不确定这些陈述之间有什么区别 import * as react from 'react' 和 import react from 'react' 提前致谢!
我正在使用最新的稳定版本的 react、react-native、react-test-renderer、react-dom。 然而,react-native 依赖于 react@16.0.0-alp
是否 react 原生 应用程序开发可以通过软件架构实现,例如 MVC、MVP、MVVM ? 谢谢你。 最佳答案 是的。 React Native 只是你提到的那些软件设计模式中的“V”。如果你考虑其
您好我正在尝试在我的导航器右按钮中绑定(bind)一个功能, 但它给出了错误。 这是我的代码: import React, { Component } from 'react'; import Ico
我使用react native创建了一个应用程序,我正在尝试生成apk。在http://facebook.github.io/react-native/docs/signed-apk-android.
1 [我尝试将分页的 z-index 更改为 0,但没有成功] 这是我的codesandbox的链接:请检查最后一个选择下拉列表,它位于分页后面。 https://codesandbox.io/s/j
我注意到 React 可以这样导入: import * as React from 'react'; ...或者像这样: import React from 'react'; 第一个导入 react
我是 react-native 的新手。我正在使用 React Native Paper 为所有屏幕提供主题。我也在使用 react 导航堆栈导航器和抽屉导航器。首先,对于导航,论文主题在导航组件中不
我有一个使用 Ignite CLI 创建的 React Native 应用程序.我正在尝试将 TabNavigator 与 React Navigation 结合使用,但我似乎无法弄清楚如何将数据从一
我正在尝试在我的 React 应用程序中进行快照测试。我已经在使用 react-testing-library 进行一般的单元测试。然而,对于快照测试,我在网上看到了不同的方法,要么使用 react-
我正在使用 react-native 构建跨平台 native 应用程序,并使用 react-navigation 在屏幕之间导航和使用 redux 管理导航状态。当我嵌套导航器时会出现问题。 例如,
由于分页和 React Native Navigation,我面临着一种复杂的问题。 单击具有类别列表的抽屉,它们都将转到屏幕 问题陈述: 当我随机点击类别时,一切正常。但是,在分页过程中遇到问题。假
这是我的抽屉导航: const DashboardStack = StackNavigator({ Dashboard: { screen: Dashboard
尝试构建 react-native android 应用程序但出现以下错误 info Running jetifier to migrate libraries to AndroidX. You ca
我目前正在一个应用程序中实现 React Router v.4,我也在其中使用 Webpack 进行捆绑。在我的 webpack 配置中,我将 React、ReactDOM 和 React-route
我正在使用 React.children 渲染一些带有 react router 的子路由(对于某个主路由下的所有子路由。 这对我来说一直很好,但是我之前正在解构传递给 children 的 Prop
当我运行 React 应用程序时,它显示 export 'React'(导入为 'React')在 'react' 中找不到。所有页面错误 see image here . 最佳答案 根据图像中的错误
当我使用这个例子在我的应用程序上实现 Image-slider 时,我遇到了这个错误。 import React,{Component} from 'react' import {View,T
我是一名优秀的程序员,十分优秀!