在我的网站上,我正在上传图像并需要返回该图像的数据 URI,但我无法弄清楚如何这样做(它必须是服务器端)。
我尝试了以下代码,但它似乎对文件名进行了编码。
@RequestMapping(value="/path/toDataURL", method=RequestMethod.POST, headers = "content-type=multipart/form-data")
public @ResponseBody String uploadMultipart(HttpServletRequest request, HttpServletResponse response, @RequestParam("file") MultipartFile multiPart) {
try {
return "data:image/png;base64," + Base64.encodeBase64(multiPart.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
Run Code Online (Sandbox Code Playgroud)
如何获取图像的数据 URI?
$(document).on("click", "li", function() {alert("A list item was clicked");}
Run Code Online (Sandbox Code Playgroud)
我正在使用上面的代码对每个列表项执行操作,但列表分隔符也正在执行此事件.
我设法将我的关闭按钮排除在外
$(document).on("click", "li", function() {
if (this.id !== "closeButton") {
alert("A list item was clicked");
}
});
Run Code Online (Sandbox Code Playgroud)
但是我不能阻止它出现在列表分隔符上.我试着无济于事
$(document).on("click", "li", function() {
if (this.class !== "ui-li-divider") {
alert("A list item was clicked");
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个有问题的JSFiddle:http://jsfiddle.net/2g3w5/
在我的表单中,我想在用户关注它们时将表单控件设置为不变,以隐藏在触摸和无效字段时显示的验证消息.
我怎样才能做到这一点?
我试过写一个指令,但一直无法让它工作.我可以在控制台中看到指令中的值从true变为false但是表单控件没有更新.
HTML:
<form name="userForm" ng-submit="submitForm(userForm.$valid)" novalidate="">
<div class="form-group">
<label>Name*</label>
<input type="text" name="name" class="form-control" ng-model="user.name" untouch="userForm.name" />
<h3>Touched: {{userForm.name.$touched}}</h3>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
指示:
validationApp.directive('untouch', function() {
return {
restrict : 'A',
require: 'ngModel',
scope: {
untouch : '='
},
link: function(scope, element) {
element.bind('focus', function() {
console.log(scope.untouch.$touched);
scope.untouch.$setUntouched();
console.log(scope.untouch.$touched);
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
我浏览了几篇有类似问题的帖子,但找不到解决我问题的帖子。其他人似乎都在使用另一个相同大小或按值的数组进行排序。
我有两个看起来像这样的数组:
var allCategories = ['Campus', 'Building', 'Floor', 'Room', 'Lecture Theatre', 'Lab'];
var currentCategories = ['Room', 'Lab', 'Campus'];
Run Code Online (Sandbox Code Playgroud)
我怎样才能排序currentCategories,以便顺序匹配allCategories?
期望的输出:
currentCategories --> ['Campus', 'Room', 'Lab'];
Run Code Online (Sandbox Code Playgroud) javascript ×3
angularjs ×1
arrays ×1
data-uri ×1
forms ×1
html-lists ×1
java ×1
jquery ×1
multipart ×1
sorting ×1