Building Applescript ObjectSpecifier With Name in Javascript - javascript

Is there a way to build an ObjectSpecifier using name instead of array number in Javascript Applescript?
search = ObjectSpecifier().buttons["Add"].value
items = items.groups.whose({_match:[search,"Selected"]})
The index for "add button" is different in each item, so if I build the ObjectSpecifier with buttons[3] Instead of buttons["Add"], it only returns the items that have add button at the index 3. I also tried "ObjectSpecifier().buttons.byName("Add").value", but it doesn't work.
Thanks!!!

buttons["Add"].value should work. Make sure all the items in the arrays you're filtering have buttons["Add"] in them. If not, filter out the ones who don't have buttons["Add"] first, and then filter again with buttons["Add"].value.

Related

Heatmap DC.js - how to filter multiple items manually

I'm working on a heatmap chart using dc.js. During the page loads, i want to manually filter the heatmap.
For example, if it filter using this heatmap.filter("30,0"); it works when the page loads. but when i try to filter multiple values using the .filter() function, it didnt work.
I tried doing this just for testing.
var test = [];
test.push("30,0");
test.push("40,2");
heatmapChart.filter(test);
Though it works if its only one item, but if i add another array item, the chart breaks. Is there a specific way to filter multiple items manually?
Yes, but there are a few layers of weird between here and there.
First, the actual filter items are constructed using dc.filters.TwoDimensionalFilter - I think your comma separated strings are only working by accident.
Second, the chart has already overridden .filter() so if you want to get at the base version which can handle multiple items, you need to call chart._filter() instead.
Finally, and weirdest of all, the syntax for filtering on multiple items is to supply an array containing a single array of filter items.
Putting these all together,
var ff = [dc.filters.TwoDimensionalFilter([0,2008]),
dc.filters.TwoDimensionalFilter([3,1994]),
dc.filters.TwoDimensionalFilter([9,2000])];
heatmapChart._filter([ff]);
works with the heatmap filtering example. Note the array of array of filters!

How to use linq.js except

I am trying to use linq.js to remove a object from a array. I am customizing highcharts and i need to modify the series. I identified the object I want to remove using .where. When I run it through the Except it is not throwing any errors. it just doesn't filter the object out.
object that I want to remove from the series
var matchingSeries = Enumerable.From(series).Where('x => x.options.id == "' + item + '"').First();
trying to get this to work
var newSeries = Enumerable.From(series).Except(matchingSeries).ToArray();
I would like to use the id as the identifier. the id is nested in matchingSeries.options.id
In LINQ in C#, Except deals with two lists. Remove the First() call from your first statement to return a list of items that can be matched against the first list.

Ember filterBy - using more than one value to filter

How can I use more than one value to filter a list using the filterBy function?
My scenario is - I have a list of consoles which I want to filter based on the console_id.
Unfortunately, I don't have control over the JSON so each consoles has a different ID. I would like to loop through the Console IDs within the nested assignedConsole JSON and then filter through the root assignedConsole JSON.
I can get the console ID of the first object and place it into the filter but I don't know how I can use two values
I have created a emberjs bin to demonstrate my problem: http://emberjs.jsbin.com/kojute/2/
After some clarification from my previous answer, I realized you want to filter by console instead of filtering the assignedConsole values. My suggestion is to add a selectedConsole property on the controller, and display the array of assignedConsoles for the selected console.
Working JSBin: http://jsbin.com/nuroyuvuta/9
EDIT: See my other answer for the working solution!
I would suggest creating a computed property on your model or your controller that flattens that nested structure for you:
allConsoles: function() {
return this.get('consoles')
.mapProperty('assignedConsoles').reduce(function(a, b) {
return a.concat(b);
})
.uniq();
}.property('consoles.#each')
This will first get all of the items from the consoles property, then map all of their assignedConsoles to an intermediate value, which is then reduced by adding all the assignedConsoles together. The final uniq() call just removes any duplicates found in the array.

Underscore JS, Grouping by an array Attribute.

I'm trying to use Javascript to group an array by one of it's attributes.
Essentially I have a list of e-mail templates, and I'm trying to group them by the category that they are in so that I can make a collapsible accordion with it later.
I think I might have the syntax of underscore JS wrong, or I'm addressing my array incorrectly. Currently I am calling groupby using the following command:
console.log(_.groupBy(result, 'im_category'));
but my array looks like the 'im_category' property is hidden under the attributes function. I'm not sure how to get there.
I've attached my console.log of what the array looks like and what happens when I run that command. (I get three different objects when I should get 2 if it's working correctly. )
Your im_category is a property of the attributes object in your businessEntity - _.groupBy is looking for properties of businessEntity. You need to create a function as iteratee:
var grouped = _.groupBy(result, function (item) {
return item.attributes.im_category;
});
http://jsfiddle.net/jwnzh8w0/

Multiple grep for a single array/ Faceted search

I have a long array with multiple items per object and I have to start to exclude items depending on what someone selects as a check box, you can see a basic idea working here
http://jsfiddle.net/caseybecking/QwtFY/
My question is how do I start to narrow the list without having to do a check on how man y items they have checked, also this doesn't work if they check multiple items per "Fit" or "Wash"
To elaborate further my objectives. I need to store object(s) that only contain the specific item(s) the user wants to FILTER down to. All this is is a ginat filter of multiple pieces of a long array.
Sounds like you want something like .serialize() or .serializeArray() -- then you can send this data to your server or use the serialized array to filter the json object. You'll need to make sure each input element has a name attribute. In the below fiddle I've removed the hideous boxChecked function as haven't a clue what your trying to achieve in that. Anyway:
Fiddle: http://jsfiddle.net/zZtyy/

Categories

Resources