我试图区分OnClick函数中的左键和右键单击.但,
var r = React.createClass({
handleClick : function(e){
//left click
if(e.which==1){
//Do something
}
},
render : function(){
return <p onClick={this.handleClick}>Something </p>
}
});
Run Code Online (Sandbox Code Playgroud)
结果是合成事件未定义的e.which.如何区分左右点击?
为什么
grep -c '^\n' myfile.txt
Run Code Online (Sandbox Code Playgroud)
当文件中有空行时返回0?
如果有一个空行,它会以新行开头吗?
如果我错了,请纠正我.
我正在尝试构建一个组件,
pre出于文档的目的显示子DOM一种解决方案是将JSX作为单独的一部分传递prop.这使得它重复,因为我已经能够通过它访问它this.props.children.理想情况下,我只需要以某种方式将childrenprop 转换为a,string以便我可以在a中呈现它pre以显示"此代码生成此结果".
这就是我到目前为止所拥有的
class DocumentationSection extends React.Component{
render(){
return <div className="section">
<h1 className="section__title">{heading || ""}</h1>
<div className="section__body"> {this.props.children}</div>
<pre className="section__src">
//Change this to produce a JSX string from the elements
{this.props.children}
</pre>
</div>;
}
}
Run Code Online (Sandbox Code Playgroud)
'<Div className='myDiv'>...</Div>当我将DocumentationSection渲染为时,如何以格式获取jsx字符串
<DocumentationSection heading='Heading 1'>
<Div className='myDiv'>...</Div>
</DocumentationSection>
Run Code Online (Sandbox Code Playgroud)
谢谢.
编辑:
我试过toString,它dint work,给了[object Object]
我正在尝试使用angularjs中的json对象填充配置文件页面.我正在使用指令.我有一个profile指令,它有profile-section指令作为子节点.配置文件部分具有作为子项的配置文件子部分指令.我需要在角度开始编译之前和角度完成渲染模板之后运行一个片段.
我试过了
app.run()
$timeout
$evalAsync
$(document).ready()
$scope.$broadcast
postLink function
Run Code Online (Sandbox Code Playgroud)
这是我的代码的骨架
var app = angular.module("profile",[]);
app.controller("profileController",['$scope',function($scope){
var ctrl = this;
}])
.controller("profileSectionController",['$scope',function($scope){
//$scope.$emit('dataloaded');
}])
.directive("profile",[function(){
return {
transclude:true,
restrict:'EA',
replace:true,
templateUrl:'/sstatic/angular_templates/de/profile.html',
scope:{
person:"="
},
controller:'profileController',
compile:function(elem,attrs,transclude){
return {
pre : function link(scope,elem,attrs,ctrl){
//angular.element(elem).find(".candidate-name").append(scope.person.name);
//$(elem).css({"display":"none"});
},
post : function link(scope,elem,attrs,ctrl){
//angular.element(elem).find(".candidate-name").append(scope.person.name);
//$(elem).css({"display":"block"});
}
}
}
}
}])
.directive("profileSection",[function(){
return {
transclude:true,
restrict:'EA',
replace:true,
require:'^profile',
templateUrl:'/sstatic/angular_templates/de/profile-section.html',
scope:{
title:"@",
right:"=",
sub:"="
},
controller:"profileSectionController",
compile:function(elem,attrs,transclude){
return {
pre : function link(scope,elem,attrs,ctrl){
//angular.element(elem).find(".candidate-name").append(scope.person.name);
},
post : …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作类似于原生闹钟应用的应用.所以,这是我正在寻找的理想结果.AlarmGoOffActivity接收待处理的意图,它会触发并显示闹钟,并通过按钮和解除按钮完成.它必须始终作为单个实例运行.实例应该在主页/后退按钮和通知图标的帮助下移动前景/背景(通知与警报同时发布)
但是,从我写的代码中,我能够
1)显示通知和警报.单击通知时,无论它在何处(前景或背景),都会将其置于前台.
2)当活动进入前景时,在实际报警屏幕之前显示白色屏幕和操作栏.
这就是我必须要做的
1)当用户检查警报并按下主屏幕或后退按钮并且活动进入后台时,我需要在通知的帮助下将其提前.2)但是,如果活动已经在前台并且单击了通知图标,则不会发生任何事情.
如果您可以在此代码中建议我需要更改的内容,那将会很棒.
AndroidManifest.xml中
<activity
android:name="com.alarm.productive.justalarm.Activities.AlarmGoOffActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait">
</activity>
Run Code Online (Sandbox Code Playgroud)
AlarmGoOffActivity.java 通知部分
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.clock_logo)
.setContentTitle(utilFunctions.toCamelCase(currentAlarmInView.getName()))
.setContentText("Snooze or Dismiss Alarm");
Intent resultIntent = new Intent(context, AlarmGoOffActivity.class);
resultIntent.putExtra(DBHelper.COLUMN_ID,currentAlarmInView.getId());
if(isSnooze){
resultIntent.putExtra(DBHelper.TASK_TITLE,"snooze");
}
resultIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(AlarmGoOffActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
1001,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager =
(NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(currentAlarmInView.getId(), mBuilder.build());
Run Code Online (Sandbox Code Playgroud) 输入
((Sass and Javascript) or (Python and Scala))
Run Code Online (Sandbox Code Playgroud)
分隔符 - "("和")"
输出是一个数组,其中分隔符作为元素出现
["(","(","Sass and Javascript",")","or","(","Python and Scala",")",")"]
Run Code Online (Sandbox Code Playgroud)
我面临的问题是这个.
var arr = "((Sass and Javascript) or (Python and Scala))".split(/[(|)]/);
console.log(arr);
document.getElementById("output").innerHTML = arr;Run Code Online (Sandbox Code Playgroud)
<div id="output"></div>Run Code Online (Sandbox Code Playgroud)
当我在字符串上使用split时,我将丢失"("和")"字符,因为它们可能出现在字符串中的任何位置,我将需要手动将它们插入到数组中.在JS中有更好的方法吗?