extjs searching deep into store data? - extjs
In the Flex app, the metadata is loaded as xml which has very good functions for searching deep into the xml nodes. In the extjs version I have converted the xml data to json, keeping the deep hierarchical content, and am loading to an extjs Store using a json reader. I have not created a model, deeming this not necessary as the model does not add add any search functionality(?). I am looking at store.find, store.findBy which can use a function, store.findRecord etc, but these functions look very 'one-levelish'. I need to go to the 'Tabs' "node", find its child 'Tab' with 'Name' of 'Tab1', and find the value of its attribute 'Title' ... am using the description "node" but it is hierarchical json data. Am I missing store functionality that would do this, should I use the store's raw json data - does json have better search functionality, or shall I revert to brute-force javascript by looping through all the "nodes"? I was hoping to avoid looping and find a function of some kind. As always, tia
Well, what I understood from our comments is that you need a kinda storage to access your JSON data as quickly and easily as possible.
JSON means JavaScript Object Notation, so it's an object!
Ok, I give you two examples.
First of all, setup JSON data:
{
"users": [{
"user": {
"id": 0 ,
"name": "foo" ,
"age": 22 ,
"skills": [{
"type": "bowcrafting" ,
"skillLevel": 50 ,
"levels": [10, 25, 50, 75, 90, 95, 99, 100]
}]
}} , {
"user": {
"id": 1 ,
"name": "bar" ,
"age": 71 ,
"skills": [{
"type": "fencing" ,
"skillLevel": 32 ,
"levels": [10, 25, 50, 90, 95, 99, 100]
} , {
"type": "swordsmanship" ,
"skillLevel": 73 ,
"levels": [10, 25, 50, 75, 80, 85, 90, 95, 99, 100]
}]
}} , {
"user": {
"id": 2 ,
"name": "foobar" ,
"age": 132 ,
"skills": [{
"type": "tactics" ,
"skillLevel": 90 ,
"levels": [10, 25, 50, 90, 95, 99, 100]
} , {
"type": "carpentery" ,
"skillLevel": 86 ,
"levels": [10, 25, 50, 75, 90, 95, 99, 100]
} , {
"type": "hiding" ,
"skillLevel": 100 ,
"levels": [10, 25, 50, 65, 75, 80, 85, 90, 95, 99, 100]
}]
}
}]
}
And now here we got two ways to follow:
First way: we can imagine the above JSON saved into a file called nested-json.json and we read it with a simple store. Than, we can use findBy search to find what we need:
var jstore = Ext.create ('Ext.data.Store', {
fields: ['id', 'name', 'age', 'skills'] ,
proxy: {
type: 'ajax' ,
url: 'nested-json.json' ,
reader: {
type: 'json' ,
root: 'users' ,
record: 'user' ,
idProperty: 'id'
}
} ,
autoLoad: true
});
Ext.create ('Ext.button.Button', {
text: 'Push me' ,
renderTo: Ext.getBody () ,
handler: function (btn) {
var index = jstore.findBy (function (user, id) {
// Here's the hint
if (user.data.skills.skillLevel === 50) return id;
else return -1;
});
if (index != -1) {
// It will print 'foo' because it's the user
// that has the skillLevel equal to 50
console.log (jstore.getAt(index).get ('name'));
}
}
});
The other way is to imagine the above JSON as an object, read directly from a raw JSON data. At this point, just use it as a javascript object:
// Users model: required by JSON reader
Ext.define ('Users', {
extend: 'Ext.data.Model' ,
fields: ['id', 'name', 'age', 'skills']
});
// JSON reader
var jreader = Ext.create ('Ext.data.reader.Json', {
model: 'Users' ,
root: 'users' ,
record: 'user' ,
idProperty: 'id'
});
// Reads records directly from raw JSON
var users = jreader.readRecords ({
"users": [{
"user": {
"id": 0 ,
"name": "foo" ,
"age": 22 ,
"skills": [{
"type": "bowcrafting" ,
"skillLevel": 50 ,
"levels": [10, 25, 50, 75, 90, 95, 99, 100]
}]
}} , {
"user": {
"id": 1 ,
"name": "bar" ,
"age": 71 ,
"skills": [{
"type": "fencing" ,
"skillLevel": 32 ,
"levels": [10, 25, 50, 90, 95, 99, 100]
} , {
"type": "swordsmanship" ,
"skillLevel": 73 ,
"levels": [10, 25, 50, 75, 80, 85, 90, 95, 99, 100]
}]
}} , {
"user": {
"id": 2 ,
"name": "foobar" ,
"age": 132 ,
"skills": [{
"type": "tactics" ,
"skillLevel": 90 ,
"levels": [10, 25, 50, 90, 95, 99, 100]
} , {
"type": "carpentery" ,
"skillLevel": 86 ,
"levels": [10, 25, 50, 75, 90, 95, 99, 100]
} , {
"type": "hiding" ,
"skillLevel": 100 ,
"levels": [10, 25, 50, 65, 75, 80, 85, 90, 95, 99, 100]
}]
}
}]
});
// Here's the magic
Ext.each (users.records, function (user) {
console.log ('*** USER ***');
console.log (user);
console.log ('id: ' + user.get ('id'));
console.log ('name: ' + user.get ('name'));
console.log ('age: ' + user.get ('age'));
Ext.each (user.get ('skills'), function (skill) {
console.log ('*** SKILL ***');
console.log (skill);
console.log ('type: ' + skill.type);
console.log ('level: ' + skill.skillLevel);
console.log ('*** LEVELS ***');
Ext.each (skill.levels, function (level) {
console.log (level);
});
});
});
Here's a jsfiddle to test this last one: jsfiddle
I hope to have understood what you requested. If I didn't, please let me know with an example made by yourself ;)
Related
MongoDB update change/convert an array with string elements to an array with object elements using the existing/current value within that object
I am learning MongoDB (5.6) and have a collection with documents like this: [ { "_id": { "$oid": "62642b53df03395a48eba4d3" }, "title": "Chemical Biology", "authors": [ "625861411edf9d62ec72c889" ], "year": 1947, "sentences": [ "sentence 001", "sentence 002" ] } ] I want to update the array "sentences" to an array of objects (in all the documents of the collection) using the existing value. I expect it like this: [ { "_id": { "$oid": "62642b53df03395a48eba4d3" }, "title": "Chemical Biology", "authors": [ "625861411edf9d62ec72c889" ], "year": 1947, "sentences": [ { "order_chem": 50, "order_bio": 50, "order_science": 50, "order_school": 50, "value": "sentence 001" }, { "order_chem": 50, "order_bio": 50, "order_science": 50, "order_school": 50, "value": "sentence 002" } ], } ] So far this query is the nearest thing I have achieved: db.collection.update({}, [ { "$set": { "sentences": { "value": {"$arrayElemAt": ["$sentences", 0]}, //"value": "$sentences", "order_chem": 50, "order_bio": 50, "order_science": 50, "order_school": 50 } } } ], { multi: true }) Which of course is producing nearly what I want, but not exactly (since I hard quoted the index to 0). If I could gain access to the current index/value of the array sentences in each loop, I can get the desired result. [ { "_id": ObjectId("62642b53df03395a48eba4d3"), "authors": [ "625861411edf9d62ec72c889" ], "sentences": [ { "order_chem": 50, "order_bio": 50, "order_science": 50, "order_school": 50, "value": "sentence 001", }, { "order_chem": 50, "order_bio": 50, "order_science": 50, "order_school": 50, "value": "sentence 001" } ], "title": "Chemical Biology", "year": 1947 } ] Mongo Playground How can I access the exact numeric array index or element/content in each loop? Thanks for your patience to read this far. Can you please advice how to use the current/existing value of a numerical array field and convert the same field to an object array using the current value? Thanks in advance.
As you are working update with aggregation pipeline, you can use $map to iterate elements in sentences and return new sentences array. db.collection.update({}, [ { "$set": { "sentences": { $map: { input: "$sentences", in: { "order_chem": 50, "order_bio": 50, "order_science": 50, "order_school": 50, value: "$$this" } } } } } ], { multi: true }) Sample Mongo Playground
angularjs chartjs legend undefined
Can anyone figure out why the legend is undefined? here is a plunker https://plnkr.co/edit/uSbRpx5w7nHvGQ3OG3x2?p=preview here is the code $scope.chartData = { data: [20, 20, 20, 20, 20, 20, 20], labels: [ "Joe", "Jason", "Mark", "Mike", "Ryan", "Sean", "Stephanie" ], series: ['Year 2016',] }; i have made 2 examples. the top one works, the one below it doesn't Any idea?
In charts the data-set must be an array of data, where the data in-turn is itself an array i.e)data-set: [data_1, data_2, data_3], where data_1=[1,2,3,4,5]; data_2=[45,32,12,25,12];.. And the series represents the corresponds the data. But here in your case the data-set is an array of numbers, which is why the legend becomes undefined. $scope.chartData = { data: [[20, 20, 20, 20, 20, 20, 20]], labels: [ "Joe", "Jason", "Mark", "Mike", "Ryan", "Sean", "Stephanie" ], series: ['Year 2016' ] };
Exact $filter in AngularJS
I have this filter: $http.get('data.json').then(function(response){ $scope.dataCopy = response.data; $scope.detMaq = $filter('filter')(angular.copy($scope.dataCopy), {index:hielo, frecuencia:frec, prod_24_h_kg:peso }, false); console.log($scope.detMaq); }); And I'm building a few div's full of info with data from that data.json. However, let's say that peso is 1.000, so in my filter I want only data that match completely to show up. This however it'll bring up data with 10.000 also, because the filter is not exact. If I put true instead of false in the filter, the page will always be blank. even though it should bring information. Am I missing something? Since it's a triple filter should I put 3 true's? Here's the json.data [{ "codigo": 21420, "desc": "......", "desc_n": "......", "sistema": "DUCHAS", "material_carroceria": "A.....", "refrigerada": "AIRE", "modelo_cubito_nombre": "ALFA", "modelo_cubito_nombre_comercial": "", "modelo_cubito_gr": 17, "prod_24_h_kg": 22, "almacen_cubitos_kg": "6", "almacen_cubitos_cubitos": 400, "ciclo_cubitos": 18, "datos_comerciales_ciclo_cubitos": 18, "compresor_cv": " 1/5", "remota": null, "potencia_w_1": 340, "potencia_w_2": 270, "voltaje": 220, "frecuencia": 50, "fases": "I", "uk": null, "gas_tipo": "R404a", "gas_carga_gr": 180, "mse_ancho": 350, "mse_alto": 590, "mse_fondo": 475, "mse_alto_con_patas": "SIN PATAS", "mce_ancho": 430, "mce_alto": 720, "mce_fondo": 540, "peso_neto": 32, "peso_bruto": 36, "index": 99, "enlace_catalogo": "..........", "familia": ".........." }, { "codigo": 21421, "desc": "...........", "desc_n": "..........", "sistema": "DUCHAS", "material_carroceria": "ACERO INOXIDABLE AISI 304", "refrigerada": "AGUA", "modelo_cubito_nombre": "ALFA", "modelo_cubito_nombre_comercial": "", "modelo_cubito_gr": 17, "prod_24_h_kg": 24, "almacen_cubitos_kg": "6", "almacen_cubitos_cubitos": 400, "ciclo_cubitos": 18, "datos_comerciales_ciclo_cubitos": 18, "compresor_cv": " 1/5", "remota": null, "potencia_w_1": 340, "potencia_w_2": 210, "voltaje": 220, "frecuencia": 50, "fases": "I", "uk": null, "gas_tipo": "R404a", "gas_carga_gr": 140, "mse_ancho": 350, "mse_alto": 590, "mse_fondo": 475, "mse_alto_con_patas": "SIN PATAS", "mce_ancho": 430, "mce_alto": 720, "mce_fondo": 540, "peso_neto": 32, "peso_bruto": 36, "index": 99, "enlace_catalogo": "....", "familia": "....." }]
Sum an array of hashes in Ruby
I have a ruby array of 3 hashes. Each peace has information about report_data (consumption of 2 types of energy) and monthes_data (same for each). Please see the code below. arr = [{:report_data=> [{:type=> {"id"=>1, "name"=>"electricity"}, :data=>[10, 20, 30, 40]}, {:type=> {"id"=>2, "name"=>"water"}, :data=>[20, 30, 40, 50]}], :monthes_data=> {:monthes=> ["jan", "feb"]}, {:report_data=> [{:type=> {"id"=>1, "name"=>"electricity"}, :data=>[15, 25, 35, 45]}, {:type=> {"id"=>2, "name"=>"water"}, :data=>[25, 35, 45, 55]}], :monthes_data=> {:monthes=> ["jan", "feb"]}, {:report_data=> [{:type=> {"id"=>1, "name"=>"electricity"}, :data=>[17, 27, 37, 47]}, {:type=> {"id"=>2, "name"=>"water"}, :data=>[27, 37, 47, 57]}], :monthes_data=> {:monthes=> ["jan", "feb"]}] I'm new to Ruby. Please help me to sum all the data by energy types. In the end I want to have one hash with report_data and monthes_data. I need the result look like: {:report_data=> [{:type=> {:"id"=>1, "name"=>"electricity"}, :data=>[42, 72, 102, 132]}, {:type=> {"id"=>2, "name"=>"water"}}, :data=>[72, 102, 132, 162]}], :monthes_data=> {:monthes=> ["jan", "feb"]}}
arr = [{:report_data=> [{:type=> {"id"=>1, "name"=>"electricity"}, :data=>[10, 20, 30, 40]}, {:type=> {"id"=>2, "name"=>"water"}, :data=>[20, 30, 40, 50]}], :monthes_data=> {:monthes=> ["jan", "feb"]}}, {:report_data=> [{:type=> {"id"=>1, "name"=>"electricity"}, :data=>[15, 25, 35, 45]}, {:type=> {"id"=>2, "name"=>"water"}, :data=>[25, 35, 45, 55]}], :monthes_data=> {:monthes=> ["jan", "feb"]}}, {:report_data=> [{:type=> {"id"=>1, "name"=>"electricity"}, :data=>[17, 27, 37, 47]}, {:type=> {"id"=>2, "name"=>"water"}, :data=>[27, 37, 47, 57]}], :monthes_data=> {:monthes=> ["jan", "feb"]}}] acc = {} arr.each do |e| e[:report_data].each_with_index do |e, idx| type = e[:type]['id'] e[:data].each_with_index do |e, idx| acc[type] = [] if not acc[type] acc[type][idx] = (acc[type][idx] or 0) + e end end end p acc outputs {1=>[42, 72, 102, 132], 2=>[72, 102, 132, 162]} You should be able to reformat this into your record
Code def convert(arr) { :months_data=>arr.first[:months_data], :report_data=>arr.map { |h| h[:report_data] }. transpose. map { |d| { :type=>d.first[:type] }. merge(:data=>d.map { |g| g[:data] }.transpose.map { |a| a.reduce(:+) }) } } end Example Half the battle in problems such as this one is visualizing the data. It's much clearer, imo, when written like this: arr = [ {:report_data=>[ {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[10, 20, 30, 40]}, {:type=>{"id"=>2, "name"=>"water"}, :data=>[20, 30, 40, 50]} ], :months_data=>{:months=>["jan", "feb"]} }, {:report_data=>[ {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[15, 25, 35, 45]}, {:type=>{"id"=>2, "name"=>"water"}, :data=>[25, 35, 45, 55]} ], :months_data=>{:months=>["jan", "feb"]} }, {:report_data=>[ {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[17, 27, 37, 47]}, {:type=>{"id"=>2, "name"=>"water"}, :data=>[27, 37, 47, 57]}], :months_data=>{:months=>["jan", "feb"]} } ] Let's try it: convert(arr) #=> {:months_data=>{:months=>["jan", "feb"]}, # :report_data=>[ # {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[42, 72, 102, 132]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[72, 102, 132, 162]} # ] # } Explanation The first thing I did is concentrate on computing the sums, so I converted this to the values of :report_data. That key, and the key-value pair of months' data, which is the same for all elements (hashes) of arr, can be added back in later. b = arr.map { |h| h[:report_data] } #=> [ # [{:type=>{"id"=>1, "name"=>"electricity"}, :data=>[10, 20, 30, 40]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[20, 30, 40, 50]} # ], # [{:type=>{"id"=>1, "name"=>"electricity"}, :data=>[15, 25, 35, 45]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[25, 35, 45, 55]} # ], # [{:type=>{"id"=>1, "name"=>"electricity"}, :data=>[17, 27, 37, 47]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[27, 37, 47, 57]} # ] # ] If you are not certain that the elements of each array will be sorted by "id", you could write: b = arr.map { |h| h[:report_data].sort_by { |g| g[:type]["id"] } } c = b.transpose #=> [ # [{:type=>{"id"=>1, "name"=>"electricity"}, :data=>[10, 20, 30, 40]}, # {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[15, 25, 35, 45]}, # {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[17, 27, 37, 47]} # ], # [{:type=>{"id"=>2, "name"=>"water"}, :data=>[20, 30, 40, 50]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[25, 35, 45, 55]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[27, 37, 47, 57]} # ] # ] e = c.map {|d| { :type=>d.first[:type] }. merge(:data=>d.map { |g| g[:data] }.transpose.map { |a| a.reduce(:+) }) } #=> [{:type=>{"id"=>1, "name"=>"electricity"}, :data=>[42, 72, 102, 132]}, # {:type=>{"id"=>2, "name"=>"water"} , :data=>[72, 102, 132, 162]}] Lastly, we need to put the put the key :report_data back in and add the months' data: { :months_data=>arr.first[:months_data], :report_data=>e } #=> {:months_data=>{:months=>["jan", "feb"]}, # :report_data=>[ # {:type=>{"id"=>1, "name"=>"electricity"}, :data=>[42, 72, 102, 132]}, # {:type=>{"id"=>2, "name"=>"water"}, :data=>[72, 102, 132, 162]} # ] # }
For clarity I've reformatted the input array and removed the :monthes_data key, since that seems to be unrelated to your question. Here's our data: TL;DR def zip_sum(arr1, arr2) return arr2 if arr1.nil? arr1.zip(arr2).map {|a, b| a + b } end def sum_report_data(arr) arr.flat_map do |item| item[:report_data].map {|datum| datum.values_at(:type, :data) } end .reduce({}) do |sums, (type, data)| sums.merge(type => data) do |_, old_data, new_data| zip_sum(old_data, new_data) end end .map {|type, data| { type: type, data: data } } end p sum_report_data(arr) # => [ { type: { "id" => 1, "name" => "electricity" }, data: [ 42, 72, 102, 132 ] }, { type: { "id" => 2, "name" => "water" }, data: [ 72, 102, 132, 162 ] } ] Explanation arr = [ { report_data: [ { type: { "id" => 1, "name" => "electricity" }, data: [ 10, 20, 30, 40 ] }, { type: { "id" => 2, "name" => "water" }, data: [ 20, 30, 40, 50 ] } ] }, { report_data: [ { type: { "id" => 1, "name" => "electricity" }, data: [ 15, 25, 35, 45 ] }, { type: { "id" => 2, "name" => "water" }, data: [ 25, 35, 45, 55 ] } ] }, { report_data: [ { type: { "id" => 1, "name" => "electricity" }, data: [ 17, 27, 37, 47 ] }, { type: { "id" => 2, "name" => "water" }, data: [ 27, 37, 47, 57 ] } ] } ] Step 1 First, let's define a helper method to sum the values of two arrays: def zip_sum(arr1, arr2) return arr2 if arr1.nil? arr1.zip(arr2).map {|a, b| a + b } end zip_sum([ 1, 2, 3 ], [ 10, 20, 30 ]) # => [ 11, 22, 33 ] zip_sum(nil, [ 5, 6, 7 ]) # => [ 5, 6, 7 ] The way zip_sum works is by "zipping" the two arrays together using Enumerable#zip (e.g. [1, 2].zip([10, 20]) returns [ [1, 10], [2, 20] ]), then adding each pair together. Step 2 Next, let's use Enumerable#flat_map to get the parts of the data we care about: result1 = arr.flat_map do |item| item[:report_data].map {|datum| datum.values_at(:type, :data) } end # result1 => [ [ { "id" => 1, "name" => "electricity" }, [ 10, 20, 30, 40 ] ], [ { "id" => 2, "name" => "water" }, [ 20, 30, 40, 50 ] ], [ { "id" => 1, "name" => "electricity" }, [ 15, 25, 35, 45 ] ], [ { "id" => 2, "name" => "water" }, [ 25, 35, 45, 55 ] ], [ { "id" => 1, "name" => "electricity" }, [ 17, 27, 37, 47 ] ], [ { "id" => 2, "name" => "water" }, [ 27, 37, 47, 57 ] ] ] Above we've just grabbed the :type and :data values out of each hash the :report_data arrays. Step 3 Next let's use Enumerable#reduce to iterate over the array of arrays and calculate a running sum of the :data values using the zip_sum method we defined earlier: result2 = result1.reduce({}) do |sums, (type, data)| sums.merge(type => data) do |_, old_data, new_data| zip_sum(old_data, new_data) end end # result2 => { { "id" => 1, "name" => "electricity" } => [ 42, 72, 102, 132 ], { "id" => 2, "name" => "water" } => [ 72, 102, 132, 162 ] } The result might look a little odd to you because we usually use strings or symbols as hash keys, but in this hash we're using other hashes (the :type values from above) as keys. That's one nice thing about Ruby: You can use any object as a key in a hash. Inside the reduce block, sums is the hash that's ultimately returned. It starts out as an empty hash ({}, the value we passed to reduce as an argument). type is the hash we're using as a key and data is the array of integers. In each iteration the next values from the result2 array are assigned to type, but sums is updated with whatever value was returned at the end of the block in the previous iteration. We're using Hash#merge in kind of a tricky way: sums.merge(type => data) do |_, old_data, new_data| zip_sum(old_data, new_data) end This merges the hash { type => data } (remember that type is the :type hash and data is the array of integers) into the hash sums. If there are any key collisions, the block will be invoked. Since we only have one key, type, then the block will be invoked if sums[type] already exists. If it does, we call zip_sum with the previous value of sums[type] and data, effectively keeping a running sum of data. In effect, it's basically doing this: sums = {} type, data = result2[0] sums[type] = zip_sum(sums[type], data) type, data = result2[1] sums[type] = zip_sum(sums[type], data) type, data = result2[3] # ...and so on. Step 4 We now have this hash in result3: { { "id" => 1, "name" => "electricity" } => [ 42, 72, 102, 132 ], { "id" => 2, "name" => "water" } => [ 72, 102, 132, 162 ] } That's the data we want, so now we just have to take it out of this weird format and put it into a regular hash with the keys :type and :data: result3 = result2.map {|type, data| { type: type, data: data } } # result3 => [ { type: { "id" => 1, "name" => "electricity" }, data: [ 42, 72, 102, 132 ] }, { type: { "id" => 2, "name" => "water" }, data: [ 72, 102, 132, 162 ] } ]
Backbone JS find the minimum value
I have this json which populates my collection (TableListCollection) of models (TableModel) { "tables": [ { "tableId": 15, "size": 8, "occupiedSeats": 0, "stakes": { "smallBlindAmount": 10, "bigBlindAmount": 20, "minBuyInAmount": 20, "maxBuyInAmount": 200 }, "gameType": "HOLDEM", "gameSpeed": "NORMAL", "friends": [] }, { "tableId": 16, "size": 8, "occupiedSeats": 0, "stakes": { "smallBlindAmount": 20, "bigBlindAmount": 40, "minBuyInAmount": 20, "maxBuyInAmount": 200 }, "gameType": "HOLDEM", "gameSpeed": "NORMAL", "friends": [] }, { "tableId": 17, "size": 8, "occupiedSeats": 0, "stakes": { "smallBlindAmount": 40, "bigBlindAmount": 60, "minBuyInAmount": 20, "maxBuyInAmount": 200 }, "gameType": "HOLDEM", "gameSpeed": "NORMAL", "friends": [] } ] } I want to find the table with the minimum smallBlindAmount. I see that I can use the _.min() but I can't figure out what I have to pass as an iterator. Thanks in advance.
Either directly on the JSON var json=... var min = _.min(json.tables,function(item) { return item.stakes.smallBlindAmount }); console.log(min.stakes.smallBlindAmount); or on your collection var json=... var c=new Backbone.Collection(json.tables); var m=c.min(function(model) { return model.get("stakes").smallBlindAmount }); console.log(m.get("stakes").smallBlindAmount); In both cases, the iterator is used to extract the values to be compared.