Once i rendered data from backend i want to remove element id from the array how can i achieve that using angularjs ?
ctrl.js
$scope.array = [{
"name": "Java Class",
"id": "javaClass",
"createdBy": "shu",
"__v": 0,
"properties": [{
"label": "Java Package Name",
"type": "String",
"editable": true,
"binding": {
"type": "property",
"name": "camunda:class"
}
}],
"appliesTo": ["bpmn:ServiceTask"]
}]
You can use delete
delete $scope.array[0].id;
Related
In order to check from my frontend application if there is or not a PDF I want to search into my nested object 'translations' for the field named "pdf_url".
{
"id": 118,
"name": "MIXY",
"thumbnail": null,
"translations": [
{
"field": "name",
"lang": "it",
"text": "MIXY"
},
{
"field": "name",
"lang": "en",
"text": "MIXY"
},
{
"field": "thumbnail",
"lang": "en",
"text": "/var/www/vhosts/mysite.com/reservedarea.mysite.com/docs/color_cards/en/mypng.png"
},
{
"field": "pdf_url",
"lang": "en",
"text": "/var/www/vhosts/mysite.com/reservedarea.mysite.com/docs/color_cards/en/mypdf.pdf"
}
]
},
{
"id": 119,
"name": "CITY",
"thumbnail": null,
"translations": [
{
"field": "pdf_url",
"lang": "en",
"text": "/var/www/vhosts/mysite.com/reservedarea.mysite.com/docs/color_cards/en/mypdf.pdf"
},
{
"field": "name",
"lang": "it",
"text": "CITY"
},
{
"field": "thumbnail",
"lang": "en",
"text": "/var/www/vhosts/mysite.com/reservedarea.mysite.com/docs/color_cards/en/mypng.png"
},
{
"field": "name",
"lang": "en",
"text": "CITY"
},
The problem I am dealing with i that for every cardObject (id: 118, 119) the pdf_url can be in position 0, 1, 2, 3 or n inside that the translations array. So when I try to access it like this, for example
cardObject?.['translations']?.[2]?.['text']
I am not always sure I check the "pdf_url" of my card. I would firstly check is the object has "pdf_url" key value using
card?.['translations'].hasOwnProperty('pdf_url')
and then? Should I loop over the translations array of objects? Is there a simple way to "reduce" or even better group my data?
You can use Array.prototype.find to find the first object in the array that has a field property with the value pdf_url.
const pdfUrl = cardObject.translations.find(translation => translation.field === 'pdf_url');
console.log(pdfUrl.text);
// /var/www/vhosts/mysite.com/reservedarea.mysite.com/docs/color_cards/en/mypdf.pdf
I have a Ant Design Form Component that takes some initital vales. I need to populate them from an array, but I it needs to be in this format.
<Form
{...layout}
name="basic"
initialValues={{ "name-0": "fdsanfdsk", "name-1": "fdsafjasf9" }} // I need the name values
// from the array here
onFinish={onFinish}
onFinishFailed={onFinishFailed}
>
My array looks like so
[{
"__typename": "FormInputVal",
"name": "name",
"_id": "291541872966369805",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "name",
"_id": "291541888089981453",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291644307943719437",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291649317517656585",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291649666387280392",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291651264892109325",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291651422325309961",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291651568083665417",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "test",
"_id": "291653619769410057",
"type": "text"
}]
I just need the names from the array, and inserted into the initalValues object in the Form Component, with a -0, -1, -2 tacked on.
I have tried the following
const test = formState?.map((item, idx) => {
return `${item.name}-${idx}:"fdsjfs"`;
});
and then I end up with another array, and I have tried turning that array test into a Object with Object.assign({},test) but then it has keys on it.
Any help would be greatley appreciated
You might consider using the reduce method.
const test = formState.reduce((obj, item, idx) => {
return { ...obj, [`${item.name}-${idx}`]: 'fdsjfs' };
}, {});
I have this schema:
{
"type": "object",
"title": "Comment",
"required": [
"comments"
],
"properties": {
"comments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"email": {
"title": "Email",
"type": "string",
"pattern": "^\\S+#\\S+$",
"description": "Email will be used for evil."
},
"spam": {
"title": "Spam",
"type": "boolean",
"default": true
},
"comment": {
"title": "Comment",
"type": "string",
"maxLength": 20,
"validationMessage": "Don't be greedy!"
}
},
"required": [
"name",
"comment"
]
}
}
}
}
This is an array of comments. I can add and remove comments.
How can I render 2 items of the array always by default ?
I've tried with maxItems and minItems but those parameters don't render items.
There are two ways to do it currently.
First is to set them in the default model so it looks something like:
$scope.model = {
"comments": [{},{}]
}
The second would be to use onChange on the array:
"onChange": function(val) { if(val.length < 2) val.push({}); }
The difference between the two being that the onChange will not allow it to drop below the minimum length you set while the first option is just for the initial default.
How to create parent child hierarchy using self-join in strongloop. I have created model name as menu.
menu.json
{
"name": "Menu",
"base": "PersistedModel",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"MenuID": {
"type": "Number",
"id": true,
"required": true
},
"Name": {
"type": "string"
},
"ParentMenuID": {
"type": "Number"
}
},
"validations": [],
"relations": {
"menus": {
"type": "hasMany",
"model": "Menu",
"foreignKey": "ParentMenuID",
}
},
"acls": [],
"methods": {}
}
Table data like:
menuId Name ParentID
1 parent 0
2 child 1
3 grandchild 2
I tried REST API call using filter but I am getting one level of data like
http://localhost:3000/api/Menus/?filter[include]=menus
[
{
"MenuID": 1,
"Name": "parent",
"ParentMenuID": 0,
"menus": [
{
"MenuID": 2,
"Name": "child",
"ParentMenuID": 1
}
]
},
{
"MenuID": 2,
"Name": "child",
"ParentMenuID": 1,
"menus": [
{
"MenuID": 3,
"Name": "grandchild",
"ParentMenuID": 2
}
]
},
{
"MenuID": 3,
"Name": "grandchild",
"ParentMenuID": 2,
"menus": []
}
]
BUT I needed output like:
[
{
"MenuID": 1,
"Name": "parent",
"ParentMenuID": 0,
"menus": [
{
"MenuID": 2,
"Name": "child",
"ParentMenuID": 1,
"menus": [
{
"MenuID": 3,
"Name": "grandchild",
"ParentMenuID": 2
}
]
}
]
}
]
Please suggest any idea or example.
After you create your model with slc loopback:model, just run slc loopback:relation and create the selfjoin as a relation.
As you now have done in your updated question. To include another you use an include filter, http://localhost:3000/api/Menus/?filter[include]=menus and to include two levels you can do like this: http://localhost:3000/api/Menus/?filter[include][menus]=menus
Suppose you have a model review, images, and the relation that you want between them is review should have multiple images. Then you have to define this relation in the json files for both the models
Review.json
"relations": {
"images": {
"type": "hasMany",
"model": "Image",
"foreignKey": ""
}
}
Image.json
"relations": {
"hotelReview": {
"type": "belongsTo",
"model": "HotelReview",
"foreignKey": ""
}
}
You can also accomplish the same using slc loopback:relation after you create both the models.
Now in order to extract the data using this relation or join, you can use the filter api's provided by loopback, and in particular use the include provide by loopback.
Sample links for loopback include and filter api
https://docs.strongloop.com/display/public/LB/Include+filter
https://docs.strongloop.com/display/public/LB/Querying+data
sample filter api, using include :-
localhost:3000/api/Review?filter[where][email]=xyz#abc.com&filter[include]=images
I have an example list of objects called properties as :
{
"properties":
[
{"type": "STRING", "validation": "^https?", "id": "9", "name": "Download URL"},
{"type": "DATE", "validation": "2015-01-01 to 2015-02-01", "id": "10", "name": "Next Upgrade"},
{"type": "INTEGER", "validation": "1..10", "id": "11", "name": "Number Of Installs"},
{"type": "BOOLEAN", "validation": "True/False", "id": "12", "name": "Admin Access"}
{"type": "ENUM", "validation": "Basic | Premium | Enterprise | Ultimate ", "id": "13", "name": "Product Edition"}
]
}
An array controller is currently used to display all these properties on the template.
Now I want to create a form in which I would want to accept all these properties as input.
Based on the type of the property, I would want to have input type in Emberjs.
I would want to write an Ember-Component which will become textbox for STRING, INTEGER and DATE types, 3-way radio-button for BOOLEAN type (Empty, True or False) and a dropdown for ENUM type.
define your own Ember.Component not Ember.View
here is working example:
//sample route
App.IndexRoute = Ember.Route.extend({
model: function() {
return [
{"type": "STRING", "validation": "^https?", "id": "9", "name": "Download URL"},
{"type": "DATE", "validation": "2015-01-01 to 2015-02-01", "id": "10", "name": "Next Upgrade"},
{"type": "INTEGER", "validation": "1..10", "id": "11", "name": "Number Of Installs"},
{"type": "BOOLEAN", "validation": "True/False", "id": "11", "name": "Admin Access"}
];
}
});
App.MyInputComponent = Ember.Component.extend({
tagName: 'input',
attributeBindings: ['customType:type'],
willInsertElement: function(){
this.set('customType', this.get('content.type'));
}
});
<script type="text/x-handlebars" data-template-name="index">
{{#each item in controller}}
{{my-input content=item}}
{{/each}}
</script>
working JSBin