My data are in the form:
data = { arr_id:[0,2,5], arr_description:["description 0","description 2","description 5"]}
My template
<script id="tmp" type="text/x-jsrender">
<ul>
{{for arr_id}}
<li>id: {{>}} **I NEED THIS->** {{:agg_desc[#Index]}} </li>
{{/for}}
</ul>
</script>
The arrays arr_id arr_description maps same data (the one with an ID the latter with a description) I want to iterate over the first one and use the #index to access the second one.
You need to pass in the arr_description array to the inner context.
Here are some relevant links:
Accessing parent data
Contextual parameters
For example, you can do this:
{{for arr_id ~arr_desc=arr_description}}
<li>id: {{>}} {{:~arr_desc[#index]}} </li>
{{/for}}
or this:
{{for arr_id}}
<li>id: {{>}} {{:~root.arr_description[#index]}} </li>
{{/for}}
Related
I want to list an item inside a specific key using a filter. Now listing like this.
Sanal
Jin
John
Tim
Jeff
Sam
John
Tim
I want like this using a filterJeffSam
Here is the Fiddle
function testCtrl($scope) {
$scope.items = {"id":"B716","day":8,"di":{"type":"normal","one":[{"name":"Sanal","age":"18"},{"name":"Jin","age":"25"}],"two":[{"name":"Jeff","age":"55"},{"name":"Sam","age":"32"}],"three":[{"name":"John","age":"34"},{"name":"Tim","age":"39"}]}};
}
<div ng-app="" ng-controller="testCtrl">
<ul>
<li ng-repeat="val in items.di">
<ul>
<li ng-repeat="value in val">{{value.name}}</li>
</ul>
</li>
</ul>
</div>
in your ng repeat change it as
<li ng-repeat="value in val | filter: val.name='jeff'">{{value.name}}</li>
I have used name you can use the value that you want ot test
Trying to display list of strings inside the template after retrieving data as JSON.
public class AutoCompSearchResult
{
public List<string> eventName = new List<string>();
}
The problem is that I need to display one by one on the list, but it displays all list between
<li> tags:
<li>EVENTS</li>
{{#each this}}
<li style="list-style: none">{{eventName}} -- </li>
{{/each}}
I have tried similar solutions https://mandrill.zendesk.com/hc/en-us/articles/205582537-Using-Handlebars-for-Dynamic-Content
but this does not output the data for my case since, I do not know the syntax for handlebars js using:
{{#each eventName}}
<li style="list-style: none">{{this}} -- </li>
{{/each}}
I want final result to be:
<ul>
<li>Item1</li>
<li>Item2</li>
...
</ul>
Chrome console of data passed:
eventName
[Object
eventName:Array[2]
0:"Dr. Dog"
1:"Laura Gibson"
__proto__
:
Array[0]
__proto__
:
Object
Finally figured out:
<ul>
<li>EVENTS</li>
{{#each this.[0].eventName}}
<li style="list-style: none">{{this}} -- </li>
{{/each}}
I had to use this.[0] to access the object and then iterate over member variable: eventName
I'm attempting to have a ng-repeat that is retrieving content from an array and displaying it on a list. The content was originally JSON, but has been stringified before being pushed into the array.
The issue is that in bootstrap, this causes the list to lose it's formatting as so:
While, I would like it to look as so:
Here is my code for the dropdown component:
<li>
<a ng-controller="appCtrl" href="#">{{greeting.text}}, world</a>
</li>
<div ng-controller="PostsCtrl">
<li ng-repeat="eachResponse in response.text">
{{eachResponse}}
</li>
</div>
<li>
My dropdown
</li>
And my code for the function that returns an array from a JSON to the response.text in the 'PostsCtrl' controller used above:
function parseTheResponse(responsedataJSON) {
var obj = JSON.parse(JSON.stringify(responsedata));
var array = [];
for (var i = 0; i < obj.connectors.length; i++ ){
stringArray.push(JSON.stringify(obj.connectors[i].name));
}
return stringArray;
}
It's because of <div> inside <ul>. Try moving ng-controller to <ul> and removing that <div> wrapper.
Like the following:
<ul ng-controller="PostsCtrl">
<li>
<a ng-controller="appCtrl" href="#">{{greeting.text}}, world</a>
</li>
<li ng-repeat="eachResponse in response.text">
{{eachResponse}}
</li>
<li>
My dropdown
</li>
</ul>
PS. Looks like you are moving on with your hello world app (taking a look at your previous questions). Good work!
this is my rename function, none of the options i've tried work, i do know, that set_id is the function to use but how?
$('#jstree').on('rename_node.jstree', function (node,obj) {
var node_id = "calculated"// calculate node_id
// tried the following 3 options ..
....
$('#jstree').jstree(true).set_id(obj,node_id); //not working
obj.instance.set_id(this,node_id)// not working either
obj.instance.set_id(obj,node_id)//nope..
So how do i set the node_id in jstree?
I looked at the API http://www.jstree.com/api/#/?q=rename&f=rename_node.jstree, and I think you have to use obj.node.
$('#jstree').jstree(true).set_id(obj.node,node_id);
obj.text should contain the new name of the node, and obj.old the old name of the node.
EDIT: The link to the API documentation does not match the code example.
Here are the correct links:
To set the ID of a node: https://www.jstree.com/api/#/?f=set_id(obj,%20id)
To rename the node (set the text value): https://www.jstree.com/api/#/?f=rename_node(obj,%20val)
The first parameter you called node is actually the event object
Example creating a node then updating his autogenerated id
$('#jstree').on('create_node.jstree', function (e, obj) {
#...
$(this).jstree(true).set_id(obj.node, 42);
}
Try the following inside your on.() function:
$(this).attr("id", node_id);
Just set property id on the element you´re using to create the nodes.
<div id="jstree">
<ul>
#foreach($feelings as $feeling)
<li id="{{{$feeling->id}}}">{{{$feeling->name}}}
<ul>
#foreach($feeling->children as $feeling_children)
<li id="{{{$feeling_children->id}}}">{{{$feeling_children->name}}}
<ul>
#foreach($feeling_children->children as $feeling_children2)
<li id="{{{$feeling_children2->id}}}">{{{$feeling_children2->name}}}
<ul>
#foreach($feeling_children2->children as $feeling_children3)
<li id="{{{$feeling_children3->id}}}">{{{$feeling_children3->name}}}
<ul>
#foreach($feeling_children3->children as $feeling_children4)
<li id="{{{$feeling_children4->id}}}"> {{{$feeling_children4->name}}}</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
I have the following list and when I call toArray or serialize it only offers me the parent <li>. I am trying to get hold of the whole hierarchy so I can store this information into a self referencing heirachy table in the database. The result here shows item_1,q_6,a_7,g_8. Where is item_3,item_4,item_5.
Thanks
<div id="example5">
<ul>
<li id="item_1">Item 1
<ul id="item_2">
<li id="item_3">Item 1 1<ul></ul></li>
<li id="item_4">Item 1 2<ul></ul></li>
<li id="item_5">Item 1 3<ul></ul></li>
</ul>
</li>
<li id="q_6">Item 2<ul></ul></li>
<li id="a_7">Item 3<ul></ul></li>
<li id="g_8">Item 4<ul></ul></li>
</ul>
</div>
<button id="fred">Click</button>
$("#fred").click(function () {
//var result = $('#example5 ul').sortable('toArray');
var result = $('#example5 ul').sortable('serialize'); //Neither work
alert(result);
});
As far as I can tell there's no default way of serializing nested sortable lists in jquery UI.
The best way to do it is to go through every child of "#example5 ul" and build your own structure (I would recommend JSON in this case) to be send to the server.