我一直在阅读一堆react
代码,我看到这样的东西,我不明白:
handleChange = field => e => {
e.preventDefault();
/// Do something here
}
Run Code Online (Sandbox Code Playgroud) 我有一个函数,我试图转换为ES6中的新箭头语法.它是一个命名函数:
function sayHello(name) {
console.log(name + ' says hello');
}
Run Code Online (Sandbox Code Playgroud)
有没有办法给它一个没有var语句的名字:
var sayHello = (name) => {
console.log(name + ' says hello');
}
Run Code Online (Sandbox Code Playgroud)
显然,我只能在定义之后使用此功能.如下:
sayHello = (name) => {
console.log(name + ' says hello');
}
Run Code Online (Sandbox Code Playgroud)
在ES6中有新的方法吗?
我有一个我创建的组件:
class Create extends Component {
constructor(props) {
super(props);
}
render() {
var playlistDOM = this.renderPlaylists(this.props.playlists);
return (
<div>
{playlistDOM}
</div>
)
}
activatePlaylist(playlistId) {
debugger;
}
renderPlaylists(playlists) {
return playlists.map(playlist => {
return <div key={playlist.playlist_id} onClick={this.activatePlaylist(playlist.playlist_id)}>{playlist.playlist_name}</div>
});
}
}
function mapStateToProps(state) {
return {
playlists: state.playlists
}
}
export default connect(mapStateToProps)(Create);
Run Code Online (Sandbox Code Playgroud)
当我render
这个页面时,我的activatePlaylist
每一个都被称为.如果我喜欢:playlist
map
bind
activatePlaylist
activatePlaylist.bind(this, playlist.playlist_id)
Run Code Online (Sandbox Code Playgroud)
我也可以使用匿名函数:
onClick={() => this.activatePlaylist(playlist.playlist_id)}
Run Code Online (Sandbox Code Playgroud)
然后它按预期工作.为什么会这样?
我有一个表,我试图一次更新多个值.这是表模式:
Column | Type | Modifiers
---------------+---------+-----------
user_id | integer |
subservice_id | integer |
Run Code Online (Sandbox Code Playgroud)
我有,user_id
并希望subservice_id
一次插入多个.是否有一种语法Postgres
可以让我做这样的事情
insert into user_subservices(user_id, subservice_id) values(1, [1, 2, 3]);
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我有一个react
带有表单的简单组件:
var AddAppts = React.createClass({
handleClick: function() {
var title = this.refs.title.getDOMNode().value;
....
var appt = {
heading: title
...
}
CalendarActions.addAppointment(appt);
},
render: function() {
return (
<div>
<label>Description</label>
<input ref="title"></input>
...
</div>
);
}
});
module.exports = AddAppts;
Run Code Online (Sandbox Code Playgroud)
我render
在另一个react
组件中尝试这个组件:
var AddAppt = require('./AddAppts');
render: function() {
return (
<div>
<AddAppt />
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you're trying …
Run Code Online (Sandbox Code Playgroud) 当我运行时,我正在尝试使用bower来下载git存储库bower install
.有没有办法将git存储库列为依赖?我在文档中找不到任何信息,但也许我在找错了地方.
我试图在表格链接到编辑页面.我知道链接正在创建,因为我可以将它们打印出来.我很接近,但我错过了一些重要的事情.我如何更改以使链接正常工作?
<h1>Scouts</h1>
<p><%= button_to "Add a new Scout", new_scout_path, :method => :get %></p>
<div class="message-board">
<table>
<tr>
<th>Name</th>
<th>Rank</th>
<th>Advancement Date</th>
<th>Age</th>
</tr>
<% @scouts.each do |scout| %>
<tr <% link_to edit_scout_path(scout) %> >
<td><%= scout.name %></td>
<td><%= scout.rank %></td>
<td><%= scout.advancement %></td>
<td><%= scout.age %></td>
</tr>
<% end %>
</table>
</div>
Run Code Online (Sandbox Code Playgroud) 我如何取一个字符串,并将其转换为jsx
?例如,如果我从a引入一个字符串textarea
,我怎么能将它转换为一个React
元素;
var jsxString = document.getElementById('textarea').value;
Run Code Online (Sandbox Code Playgroud)
我将使用什么过程在客户端上转换它?可能吗?
我试图将一个keyup事件附加到我的Angular项目中的指令.这是指令:
angular.module('clinicalApp').directive('chatContainer', function() {
return {
scope: {
encounter: '=',
count: '='
}
templateUrl: 'views/chat.container.html',
link: function(scope, elem, attrs) {
scope.count = 500;
}
};
});
Run Code Online (Sandbox Code Playgroud)
这是模板中的html:
<div class="span4 chat-container">
<div class="chat-body">
<form accept-charset="UTF-8" action="#" method="POST">
<div class="text-area-container">
<textarea id="chatBox" class="chat-box" rows="2"></textarea>
</div>
<div class="button-container btn-group btn-group-chat">
<input id="comment" class="btn btn-primary btn-small btn-comment disabled" value="Comment" ng-click="addMessage()"/>
</div>
</form>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想访问chatbox
我的链接功能并将keyup事件附加到它.我知道我可以用jQuery来获取它,但这不是Angular方式.从dom中获取元素的正确方法是什么?
我是一个noobie at React
,我正在努力做一个Bootstrap
下拉列表.我附加的html在这里:
<ul class="dropdown-menu" id="dropdown">
</ul>
Run Code Online (Sandbox Code Playgroud)
以下是我想在我的render
方法中插入我的html:
render: function() {
return (
<li><a href="#books">Books</a></li>
<li><a href="#podcasts">Podcasts</a></li>
<li><a href="#">Tech I Like</a></li>
<li><a href="#">About me</a></li>
<li><a href="#addBlog">Add a Blog</a></li>
);
}
Run Code Online (Sandbox Code Playgroud)
但当然我只能归还一个元素.这样做的正确方法是什么React
?我怎么能<li>
在这样的下拉列表中添加多个?我尝试将整个东西包裹起来<div>
,但这会弄乱我的CSS.
javascript ×4
reactjs ×4
ecmascript-6 ×2
angularjs ×1
bower ×1
postgresql ×1
react-jsx ×1
redux ×1