async get 요청으로 작동하도록 코드를 가져올 수 없습니다. 내 File todo.tag.html의 Table에 GET 요청을 통해 얻은 JSON Objects를로드하려고합니다. 내 문제는 어떻게 매개 변수를 전달할 수 있습니다. 난 내 폭동 태그에 매개 변수를 전달하고 싶지만 어떻게 해야할지 모르겠다. 나는 각 태그 = "{allTodos()}"로 태그를 시도했다. 이 메서드는 실제로 async : false를 설정하면 작동하지만 true는 true로 설정되지 않습니다. allTodos는 JSON 객체를 가져 오는 메소드입니다. 누구든지 내가 뭘 할 수 있는지 아니? 이 내 (간체) 코드 index.html을 :Riotjs에서 Ajax 비동기 요청 받기
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="./jquery-ui.css">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="stylesheet" type="text/css" href="./stylesheet.css">
<script src="./jquery-1.12.4.js"></script>
<script src="./jquery-ui.js"></script>
</head>
<body>
<script src="js/riot+compiler.min.js"></script>
<script type="riot/tag" src="todo-form.tag.html"></script>
<script type="riot/tag" src="todo.tag.html"></script>
</script>
<script>riot.mount('todoForm');</script>
<form>
<todo-form><todo-form>
<form>
</body>
</html>
todo.tag.html : 어떻게
<todo>
<table style="width:100%">
<tr>
<td><label><input type="checkbox" checked={ done }> { title }</label> </td>
<td><p>{ due_date } <button type="button">Delete</button></p></td>
</tr>
</table>
</todo>
할 일-form.tag.html
<todo-form>
<fieldset class="Issues">
<legend>Issues</legend>
<ul>
<todo each="{ allTodos() }"> </todo> // This here is the problem
</ul>
</fieldset>
<script>
// return all todos
allTodos(){
var test = [];
var url = 'http://myurl.com/projects'; //random adress
$.ajax({
url: url,
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
test = data;
}
});
return test;
}
</script>
</todo-form>
그게 내 JSON 객체가 표시됩니다.
[
{
"done": true,
"title": "tests",
"due_date": "2016-11-20T23:00:00.000Z"
},
{
"done": true,
"title": "tests2",
"due_date": "2016-11-20T23:00:00.000Z"
}
]
아주 많이 저를 위해 그것을 해결합니다. 또 다른 방법으로 {opts.t} 매개 변수를 배열에 저장할 수 있습니까? 나는 항상 정의되지 않은 것을 얻는다. – member2
opts.t는 단일 객체입니다. 아니면 배열에 집어 넣을 것을 의미합니까? var ts = []; ts.push (t)? 또는 정확히 무엇을 의미합니까? 당신은 적절한 대답을 줄 수 있도록 세부 사항을 가진 새로운 질문을 만들 수 있습니다. – vitomd
미안하지만, 나쁘게 설명했습니다. 그러나 push (t)는 내가 원했던 것입니다. 감사 – member2