在服务器上传之前,有以下代码进行预览:
$(function(){
var preview = $(".preview");
$("#menu_image").change(function(event){
var input = $(event.currentTarget);
var file = input[0].files[0];
var reader = new FileReader();
reader.onload = function(e){
var img = new Image;
img.onload = function() {
if ((img.with != 160) || (img.height != 160)) {
return;
}
preview.attr("src", img.src);
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
});
});
Run Code Online (Sandbox Code Playgroud)
但是这段代码不会检查文件的类型.我该怎么做?提前致谢.
有一些字符串(例如,“ s”):
import 'lodash';
// TODO import jquery
//import 'jquery';
/*
Some very important comment
*/
Run Code Online (Sandbox Code Playgroud)
如何删除“ s”字符串中的所有注释?我应该使用一些正则表达式吗?我不知道。
我的React/Redux组件用于处理Google地图:
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { changeMapCenter } from '../actions'
class Map extends Component {
componentDidMount() {
let script = document.createElement('script')
script.setAttribute('type', 'text/javascript')
script.setAttribute('src', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyCXg-YGJF&callback=initMap')
document.getElementsByTagName('head')[0].appendChild(script)
window.initMap = () => {
this.map = new google.maps.Map(document.getElementById('map'), {
center: this.props.defaultCenter,
zoom: this.props.defaultZoom
});
this.map.addListener('center_changed', (event) => {
let center = {
lat: this.map.getCenter().lat(),
lng: this.map.getCenter().lng()
}
this.props.onMapCenterChanging(center)
});
}
}
render() {
return (
<div id='map'></div>
);
}
}
const mapStateToProps …Run Code Online (Sandbox Code Playgroud) 我正在开发一些Android应用程序,我有带有2个选项卡的ActionBar.当用户选择第二个选项卡时,我需要在ActionBar上显示2个图标.我有以下代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
mOptionsMenu=menu;
menu.getItem(0).setVisible(false);
menu.getItem(1).setVisible(false);
return true;
}
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
if (tab.getPosition()==1) {
mOptionsMenu.getItem(0).setVisible(true);
mOptionsMenu.getItem(1).setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码不起作用.请告诉我,我怎样才能满足我的需求?
有以下任务:我需要获取一个时间与另一个时间之间的分钟数:例如,“8:15”和“7:45”之间。我有以下代码:
(Time.parse("8:15") - Time.parse("7:45")).minute
Run Code Online (Sandbox Code Playgroud)
但我得到的结果为“108000.0 秒”。
我该如何修复它?
有以下代码:
handleFileSelect = (evt) ->
console.log(1)
file = evt.currentTarget.files[0]
reader = new FileReader()
reader.onload = (evt) ->
$scope.$apply ($scope) ->
$scope.myImage = evt.target.result
reader.readAsDataURL(file)
angular.element(document.querySelector('#fileInput')).on('change', handleFileSelect)
Run Code Online (Sandbox Code Playgroud)
和HTML:
<div class="form-group ng-scope">
<label class="col-sm-2 control-label" for="image">Image:</label>
<div class="col-sm-10">
<div class="cropFile">
<input id="fileInput" type="file">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在更改某个文件后在控制台中获得"1" #fileInput.但是当我选择文件时,我什么也得不到.我该如何解决?谢谢!
我需要将一些内容数据提供给我的控制器:
state('admin.businesses.employees.all', {
resolve: {
executorsListTitle: 'All employees',
executorsEmptyListMessage: 'Add the first employee'
},
url: '/all',
controller: 'ExecutorsController',
templateUrl: 'templates/admin/executors/index.html'
})
Run Code Online (Sandbox Code Playgroud)
和一个控制器代码:
module.controller(
'ExecutorsController',
[
'$scope', '$rootScope', '$state',
'$stateParams', '$modal', 'executorsListTitle',
'executorsEmptyListMessage', 'Executor',
function($scope, $rootScope, $state, $stateParams, $modal, executorsListTitle, executorsEmptyListMessage, Executor) {
// Some code
}
)
Run Code Online (Sandbox Code Playgroud)
但是当我试图进入这种状态时,我无法做到这一点 - 按下按钮就什么都不做; 如果我从状态描述中删除了解决方案,那就很好.我做错了什么?谢谢!
有以下HTML代码:
<div class="preloader">
<img src="img/preloader.gif">
<span>
<strong>????????? ??????...</strong>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS代码:
.preloader span {
display: inline-block;
vertical-align: middle;
margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
我垂直对齐div中的span,但现在我需要水平对齐span.我试过使用'margin:0 auto',但它不起作用.请告诉我,我该怎么办?谢谢!我需要具有左对齐的图像和具有中心对齐的文本作为结果.
有以下控制器定义:
angular.module('app.controllers', []).controller('HomeController', [
'$scope', '$modal', 'Point', function($scope, $modal, Point) { //some action }
Run Code Online (Sandbox Code Playgroud)
我想测试这个控制器:
describe('HomeController', function() {
beforeEach(module('app.controllers'));
var $controller;
beforeEach(inject(function(_$controller_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));
describe('$scope.grade', function() {
it('sets the strength to "strong" if the password length is >8 chars', function() {
var $scope = {};
var controller = $controller('HomeController', { $scope: $scope });
$scope.label = '12345';
$scope.addNewPoint();
expect($scope.label).toEqual(null);
});
});
});
Run Code Online (Sandbox Code Playgroud)
"Point"是我的自定义服务,"$ modal"是Angular Bootstrap模块.我怎样才能在测试中注入它?提前致谢!
有以下代码:
<div class="first" ng-click="funcFirst()">
... Some other content
<div class="second" ng-click="funcSecond()">
</div>
... Some other content
</div>
Run Code Online (Sandbox Code Playgroud)
我想做以下事情:如果我点击"第一"div中除"second"之外的任何内容 - 执行funcFirst函数; 如果我点击"秒"div - 执行funcSecond函数.现在,如果我点击"秒",我执行funcFirst.我该怎么做?我无法改变HTML结构.提前致谢.