Does Angular Schema Form support nested array conditions - angular-schema-form

I'm using the Angular Schema Form js library for a project and have a schema with a 3 level deep array. In the form JSON I want a condition on one of the fields in the nested array. In conditions the only way I know to reference an array element in the model is to use arrayIndex but that is just the index of the inner most array. So the following condition will not work as arrayIndex will only be the correct index for prices[]:
"condition": " model.products[arrayIndex].versions[arrayIndex].prices[arrayIndex].currency == 'USD'"
Is there anyway to perform conditions on nested arrays and reference the nested array element in the model? Something like:
"condition": " model.products[parent.parent.arrayIndex].versions[parent.arrayIndex].prices[arrayIndex].currency == 'USD'"
Any help would be greatly appreciated!!

Related

Laravel Eloquent - Working with an array of JSON objects

I have an array of JSON objects within my database (as depicted by the image below)
How do I search for a specific value within it? Say I want the record where the "ends_at" field is equal to "2018-11-24 08:00:00"
I've tried using
->where('column->starts_at', '2018-11-24 08:00:00')
or even tried
->whereJsonContains('column->starts_at', '2018-11-24 08:00:00').
Within the model I've cast the column to an array - am I missing something, or can this not be done?
Use this:
->whereJsonContains('column', ['starts_at' => '2018-11-24 08:00:00'])

Order collection of array objects

After making some queryes i have a collection of array objects. But after orderByDesc the data transform in hole objects, instead of how it was (array of objects), what it happened? Is like the method orderByDesc tranform the collection in another type.
Ex:
some logic code, queries...etc
in the end
return $total->sortByDesc('date');
After using sortByDesc:
Before to sortByDesc:
Now that is in type of objects is giving some issues working with it in my javascript application (angularjs), it not a array of objects how should it be.
Try to copy the collection when sorting and use values()
$sorted = $total->sortByDesc('date');
dd($sorted->values());
Same result?

applying class in ng-repeat if contained in another array

I am querying for a collection of IDs from Parse.com and showing them in my $scope as an array.
I would like to apply a class to the items in my $scope that match any one of these IDs, placing a border around the object illustrating that it is already contained in the 'saved' array. I have tried the following however not having any luck.
ng-class="{'approved': ParseSavedExercises.indexOf(exercise.id) == -1}"
in this case my ParseSavedExercisesis my array to check against and exercise.id is what I am checking for.
here is a quick fiddle
Please see here http://jsfiddle.net/e9pr4yqj/
Yours ParseSavedExercises contains string and id is number so no id existed in ParseSavedExercises
$scope.ParseSavedExercises = ['2','3'];
change to
$scope.ParseSavedExercises = [2,3];
or use
ng-class="{'approved': ParseSavedExercises.indexOf(exercise.id.toString()) == -1}"
like here http://jsfiddle.net/1ujgvL80/

filter list with multiple checkboxes in Angularjs

I would like to filter a ng-repeat list of items with multiple catgories checkboxes.
i read this Filtering by multiple checkboxes in AngularJS and watched the videos by Egghead, but i have an error on a simple for loop and i don't understand:
ReferenceError: i is not defined
here is a plunker with the code : http://plnkr.co/edit/p538ALfs00JTFQ6mKT9j
thank you for your help
If you're going to use strict mode ('use strict';), you need to declare your variables. Your checkboxFilter uses many variables that are never defined (i included). You can get past the your initial issues by changing script.js:22-23 to:
var i,j,k,filter_cat,filter_value,filter_name,matchingItems = [];
You have three other problems after that...
Line 37, This code is looking for a property named filter_cat: items[i].filter_cat, when what you wanted was to look for a property name with the value of filter_cat, so this is what you want: items[i].[filter_cat].
Your json data has lowercase field names and your code is searching on uppercase (Type vs type)
Your json data has lowercase values and your code is searching on uppercase (Fruit vs fruit)
Here is a partial edit that gets you on the right track. You'll still need to modify your json or compare lowercase (I partially modified your json): http://plnkr.co/edit/d7p4QthXJg4ao34ATWla?p=preview

$addToSet in MongoDb with nested positional operators

I want to add a value to an array that is inside another array. My document is like:
{categories:[{categoryName:"a category", items:[{itemName:"an item", arrayOfValues:[1]}]}]}
I would like to use $addToSet to arrayValues. To do so I am doing an update with a query
table.update({"categories.items.itemName" : "anItem"}, {$addToSet: "categories.$.items.$.arrayOfValues":"10"})
but I get an error: can't append to array using string field name [$]
What am I doing wrong? Is it possible to update with nested arrays?
Thanks
Arrays inside arrays is considered bad mongodb design right now (mainly because you can't manipulate them efficiently, using $addToSet and friends). And you took it one step further and created arrays inside arrays inside arrays!
I understand that schema-less nature of MongoDB can cause a feeling that you can throw documents of any structure into it and handle them later. Unfortunately, this is not the reality. You have to know what you're doing, what features and limitations are there. In this case, you can't use positional operator to push element to a nested array.

Resources