我想将相同的事件绑定到包含组件中特定类的所有 HTML 元素
例子:
<span class="myClass">Item1</span>
<span class="myClass">Item2</span>
<span class="myClass">Item3</span>
Run Code Online (Sandbox Code Playgroud)
我想在 Angular 8+ 中做什么:
document.querySelectorAll(".myClass").forEach(item => item.addEventListener('click', event => myFunction(event));
Run Code Online (Sandbox Code Playgroud)
这甚至可能与 Angular 一起使用吗?
我做了一些搜索,但没有找到我真正需要的东西。
我需要在MatTable包含一个<span contentEditable=true></span>
在我的前端,我发送这个JSON:
"ids": [ 123421, 15643, 51243],
"user": {
"name": "John",
"email": "john@sovfw.com.br"
}
Run Code Online (Sandbox Code Playgroud)
到我的Spring Endpoint:
@PostMapping(value = "/sendToOficial")
public ResponseEntity<?> sendToOficial(@RequestBody Map<String, Object> payload) {
ObjectMapper mapper = new ObjectMapper();
List<Long> pointsIds = mapper.convertValue( payload.get("pointsIds"), List.class );
UsuarioDTO autorAlteracao = mapper.convertValue(payload.get("user"), UsuarioDTO.class);
for (Long idPoint : pointsIds) { ... }
Run Code Online (Sandbox Code Playgroud)
但我得到一个Cast Exception,因为它说它不能将Integer强制转换为Long.
我不能收到整数的"ids"数字,我希望收到Long.拜托,我怎么能这样做?
我的urls.py中有这个网址
path('foo/bar/api', foo.APIBar.as_view(), name='foo-bar-api'),
Run Code Online (Sandbox Code Playgroud)
在我的view.py中,我有这个类来处理api:
class APIBar(APIView):
def post(request, self, format=None):
date= request.POST['date']
person= get_object_or_404(Person, id=request.POST['person'])
return Response(status=status.HTTP_201_CREATED)
Run Code Online (Sandbox Code Playgroud)
我正在尝试发送此ajax:
$.ajax({
url: "{% url 'foo-bar-api' %}",
method: "POST",
data: {
date: date.val(),
person: person.val()
}
});
Run Code Online (Sandbox Code Playgroud)
但是Django它给了我这个错误:
AttributeError: 'APIBar' object has no attribute 'POST'
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样。我在其他模型中使用了相同的结构,并且像一个吊饰一样工作,但是这给了这个错误。
拜托,你能告诉我我在做什么错吗?我花了几个小时尝试修复此错误。
我想让按钮与之前表单控件中的输入文本保持在同一行。
<div class="row">
<div class="form-group col-xs-6 col-md-5 ">
<label for="">Name</label>
<input class="form-control " type="text" >
</div>
<div class="form-group col-xs-6 col-md-5 ">
<label for="">E-mail</label>
<input class="form-control " type="text" ">
</div>
<div class="form-group col-xs-6 col-md-2">
<button class="btn btn-primary">Save</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
检查这个小提琴,看看它是怎么回事: 小提琴
我试图在按钮标签上方放置一个“标签”。但我不认为这是更好和正确的方式来做到这一点。
如果String值包含任何不是数字[0-9],连字符(-),分号(;)或感叹号的不同字符,我想抛出异常(!).
例如,这是一个完全正确的字符串:1; 3; 5-9;!12-14
但这个不是:1; 3abc; 5~9;?12*41
我正在尝试使用下面的代码,但它总是失败:
String values = "1;3;5-9;!12-14"
Pattern pattern = Pattern.compile("[\\d*]|[\\;]|[\\-]|[\\!]");
if (!pattern.matcher(values).matches()) {
throw new Exception();
}
Run Code Online (Sandbox Code Playgroud)