I want to get data from rest API via javascript and show it in velocity temple.
In file example.js
AJS.toInit(function(){
var user = getCurrentUserName();
AJS.$(".....)....
...
}
function getCurrentUserName()
{
var baseUrl = AJS.params.baseURL;
var user;
AJS.$.ajax({
url: baseUrl+'/rest/gadget/1.0/currentUser',
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data
}
});
return user;
}
In file example.vm
<div class="field-group">
<label for="multiselect">Multi select</label>
<select class="multi-select" size="4" multiple="multiple" id="multiselect" name="multiselect">
#foreach ($user in $user)
<option>$user.username</option>
#end
</select>
</div>
I want to get the user variable as $user in velocity template.
Could I do that?
No, Velocity is a fassad for java objects not for javascript objects. try
$webResourceManager.requireResource("com.atlassian.auiplugin:ajs") $webResourceManager.requireResource("com.xxx.example:example-resources")
in your example.vm body and add the resource in atlassian-plugin.xml. handle the foreach loop in the js.
yes, thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.