Dust js web gives us some examples. One of them is recursion.
When I change the 'name' of the json in the 3rd section and the 'name' in 1st section to other string like 'node', the output is wrong! What am I doing wrong?
Code:
{node}{~n}{#kids}{>recursion:./}{/kids}
{
"node": "1",
"kids": [{
"node": "1.1",
"kids": [{
"node": "1.1.1"
}]
}]
}
It doesn't work because "recursion" is a template loaded in the dust context.
In dust you can load other templates by name: So when he writes this:
{>recursion:./}
He is loading a template called recursion. you can find it in the examples files.
this is the recursion template:
{
name: "recursion",
source: "{name}{~n}{#kids}{>recursion:./}{/kids}",
context: {
name: '1',
kids: [
{
name: '1.1',
kids: [
{name: '1.1.1'}
]
}
]
},
expected: "1\n1.1\n1.1.1\n"
}
You should create another template with the node fields, load it in the dust context and then just use it.
Related
I’m working on a chrome extension where I’d like to update one javascript file at runtime on button click in popup.html
Can anyone tell me is there any possibility manipulate javascript file at rutime with a button click?
For example: Javascript file want to manipulate named index.js, containing only one array object as following :
let obj1 = [
{ Name: "Peter", Dep: "Team1" },
{ Name: "Abhilasha", Dep: "Team2" }
]
New object to be added/pushed to the file index.js :
{ Name: "Ani", Dep: "Team3" }
On clicking the button on extension popup it will update the index.js with the new object and resultant array object in the index.js is as follow:
let obj1 = [
{ Name: "Peter", Dep: "Team1" },
{ Name: "Abhilasha", Dep: "Team2" },
{ Name: "Ani", Dep: "Team3" }
]
I am not sure whether file manipulation is possible from front-end using onClick event. It would be really helpful if you guys can guide me. Thanks in advance!
i'm building a quiz web-app that only serve locally on the machine. All logic & architecture are now done. But the only problem left is:how do i make the question list from "questionOptions.js" to be external on production version?
So that i can change the list with out the need to export another build version?
currently, the list is being pull from locally in development mode, and i dont have any idea to load list to be dynamic(which can be edit on final build).
Vue js
var looper = new Vue({
el: "#quiz",
data: {
questionList: require("./js/questionsOptions"),
currentQuestion: 0,
...
}
});
questionOptions.js
module.exports = [
{
title: "Soalan 1",
questionTitle: 'Ini adalah penyata soalan 1',
correctAnswer: true,
answerSelection: [
{
name: "Answer 1 A",
score: true
},
{
name: "Answer 1 B",
score: false
},
]
},
{
title: "Soalan 2",
questionTitle: 'Ini adalah penyata soalan 2',
correctAnswer: true,
answerSelection: [
{
name: "Answer 2 A",
score: true
},
{
name: "Answer 2 B",
score: false
}
]
}
]
i might want to change the list content or length in the future, just the question list only on final build. how can i achieve this?
require() is synchronous and executes at build time.
To perform an async request at runtime, you can use import(). Keep in mind, your app will need to be able to handle the asynchronous loading.
For example
data: {
questionList: [],
currentQuestion: 0,
},
async created () {
this.questionList = await import(
/* webpackChunkName: "questionOptions" */
'./js/questionsOptions'
)
}
im working with nodejs an need to get a string value from a json.
The json looks like this:
`result["DIDL-Lite"]["item"] = [ { '$': { id: '0/Spotify/Track', parentID: '0/Spotify', restricted: '0' },
'upnp:class': [ 'object.item.audioItem.musicTrack' ],
'raumfeld:section': [ 'Spotify' ],
'dc:title': [ 'Californication' ],
'upnp:artist': [ 'Red Hot Chili Peppers' ],
'upnp:album': [ 'Californication (Deluxe Version)' ],
'upnp:albumArtURI': [ [Object] ] } ]`
how can i access the dc:title (or any other) value?
I'm trying different ways, e.g. console.log(result["DIDL-Lite"]["item"]["dc:title"]);, but I simply can't get it work...
Any tips? Thank you in adavance!!
I am newbie in AngularJS. I need to create a TreeView Structure From JSON Object.
My Return JSON Object is looks like below.
var categoryTree = [{Name:'Item1', Childnodes : {}, id: 1},
{Name:'Item2', Childnodes : {
items = [
{Name:'Sub Item21', Childnodes : {}, id: 21}
{Name:'Sub Item22', Childnodes : {}, id: 22}
]
}, id: 2}];
Could you please help me to create a AngularJS Tree View.
Thanks in Advance.
You can create a Tree view using the Webix framework along with AngularJS.
https://github.com/TheAjinkya/webixTreeWithJava-
https://github.com/TheAjinkya/AngularWebixApplication
treedata = [{
id: "1",
value: "Book 1",
data: [{
id: "1.1",
value: "Part 1"
},
{
id: "1.2",
value: "Part 2"
}
]
},
{
id: "2",
value: "Book 2",
data: [{
id: "2.1",
value: "Part 1"
}]
}
];
tree = new webix.ui({
view: "tree"
});
tree.parse(treedata)
<script src="https://cdn.webix.com/edge/webix.js"></script>
<link href="https://cdn.webix.com/edge/webix.css" rel="stylesheet" />
Please use some sort of tree view module. They can make your life much easier. The only thing is that you need to re-format your data structure to the tree module style. You can write a service and do all re-formatting inside a service.
Some tree view module and plugin:
http://ngmodules.org/modules/angular.treeview
https://angular-ui-tree.github.io/angular-ui-tree/#/basic-example
I have successfully implement type ahead using angular js using this codepen.
Now my data is dynamic so I want to create my own json that should looks something like following:
$scope.states = [
{
name: "ABCD",
id: "AB"
},
{
name: "XYZ",
id: "XY"
},
{
name: "OPQR",
id: "OP"
},
{
name: "LMNO",
id: "LM"
},
{
name: "KLM",
id: "KL"
}
];
How to create like above json and store in $scope variable so I can access it using name and id separately.
Please help me...!!
I am giving by my own now cause I got it little bit late.
Solution is I have pushed the data wrong I have solved it like:
$scope.states.push({
name: "string",
id: int,
});
and I got it.