I have the following JSON data :
{
"disclaimer": "Exchange rates provided for informational purposes only and do not constitute financial advice of any kind. Although every attempt is made to ensure quality, no guarantees are made of accuracy, validity, availability, or fitness for any purpose. All usage subject to acceptance of Terms: https://openexchangerates.org/terms/",
"license": "Data sourced from various providers; resale prohibited; no warranties given of any kind. All usage subject to License Agreement: https://openexchangerates.org/license/",
"timestamp": 1475110853,
"base": "USD",
"rates": {
"AED": 3.672983,
"AFN": 66.5538,
"ALL": 122.0421,
"AMD": 473.5925,
"ANG": 1.7763,
"AOA": 165.571834,
"ARS": 15.3169,
"AUD": 1.299338,
"AWG": 1.792667,
"YER": 250.130999,
"ZAR": 13.61321,
"ZMK": 5252.024745,
"ZMW": 9.831204,
"ZWL": 322.387247
}
}
And I have defined my model as follows:
Ext.define('CurrencyConvert.model.CurrencyCode', {
extend : 'Ext.data.Model',
fields : [
{
name : 'code',
value : 'string'
},
{
name : 'rate',
value : 'float'
}
]
});
So that I can have the currency code(i.e. "USD") and the rate. But the problem is that the currency code itself is the property name of the actual rate; so how would I create my store so as to get both the code and the rate in my model ?
Ex:
For "AED": 3.672983, I want the code value to hold "AED" and rate field to hold 3.672983.
You can do like this:
Ext.define('CurrencyConvert.model.CurrencyCode', {
extend : 'Ext.data.Model',
fields : [
{
name : 'code',
value : 'string',
convert:function(v,rec){
=== Add Your Logic Here ===
}
},
{
name : 'rate',
value : 'float'
convert:function(v,rec){
=== Add Your Logic Here ===
}
}
]
});
Ext.define('CurrencyConvert.model.CurrencyCode', {
extend : 'Ext.data.Model',
fields : [
{
name : 'code',
value : 'string'
},
{
name : 'rate',
value : 'float',
convert : function(value, record) {
return jsonData.rates[record.get('code')]
}
}
]
});
Related
I need to map my List that's with in list but couldn't do it .
I tried using hasmany but it wont help .
Unless its mapping i'm unable to loop my tpl as its not detecting the proper objects.
Below is my Json:
{
"containers":[
{
"count":654,
"week":47
},
{
"count":779,
"week":48
}
],
"vessels":[
{
"count":44,
"week":47
},
{
"count":39,
"week":48
}
]
}
My model :
Ext.define('ContainerChartStore', {
extend : 'Ext.data.Model',
fields : [{
name : "containers",
type : Ext.data.Types.List
},{
name : "vessels",
type : Ext.data.Types.List
}],
hasMany: {
model: 'InboundObjects',
name: 'inboundObjects'
}
});
Ext.define('InboundObjects', {
extend: 'Ext.data.Model',
config: {
fields : [{
name : "count",
type : Ext.data.Types.NUMBERARRAY
},{
name : "week",
type : Ext.data.Types.NUMBERARRAY
}]
}
});
I have collection "groups". like this:
{
"_id" : "e9sc7ogDp8pwY2uSX",
"groupName" : "one",
"creator" : "KPi9JwvEohKJsFyL4",
"eventDate" : "",
"isEvent" : true,
"eventStatus" : "Event announced",
"user" : [
{
"id" : "xfaAjgcSpSeGdmBuv",
"username" : "1#gmail.com",
"email" : "1#gmail.com",
"order" : [ ],
"price" : [ ],
"confirm" : false,
"complete" : false,
"emailText" : ""
},
...
],
...
"buyingStatus" : false,
"emailTextConfirmOrder" : " With love, your Pizzaday!! "
}
How can I get a value of specific element? For example i need to get value of "Groups.user.confirm" of specific group and specific user.
I tried to do so in methods.js
'pizzaDay.user.confirm': function(thisGroupeId, thisUser){
return Groups.find({ _id: thisGroupeId },{"user": ""},{"id": thisUser}).confirm
},
but it returns nothing.
Even in mongo console I can get just users array using
db.groups.findOne({ _id: "e9sc7ogDp8pwY2uSX"},{"user": ""})
The whole code is github
http://github.com/sysstas/pizzaday2
Try the following query:-
db.groups.aggregate(
[
{
$match:
{
_id: thisGroupeId,
"user.id": thisUser
}
},
{
$project:
{
groupName : 1,
//Add other fields of `user` level, if want to project those as well.
user:
{
"$setDifference":
[{
"$map":
{
"input": "$user",
"as": "o",
"in":
{
$eq : ["$$o.id" , thisUser] //Updated here
}
}
},[false]
]
}
}
}
]);
The above query will give the object(s) matching the query in $match inside user array. Now you can access any field you want of that particular object.
'pizzaDay.user.confirm': function(){
return Groups.findOne({ _id: thisGroupeId }).user.confirm;
I resolved it using this:
Template.Pizzaday.helpers({
confirm: function(){
let isConfirm = Groups.findOne(
{_id: Session.get("idgroupe")}).user.filter(
function(v){
return v.id === Meteor.userId();
})[0].confirm;
return isConfirm;
},
});
But I still think that there is some much elegant way to do that.
I am having an inordinate amount of trouble trying to structure an ElasticSearch query.
I need to get the top 25 tweets based on the sum of two fields, favoritesCount and retweetCount. I also need to be able to specify a date range on the field postedCount.
So far the closest I have been able to come is
query = {
'size' : 25,
'fields' : ['retweetCount', 'favoritesCount', 'preferredUsername', 'body'],
"query": {
"range": {
"postedTime" : {
'gte' : 'now-24M',
'lte' : 'now'
}
}
},
"sort" : {
"retweetCount" : {"order" : "desc"},
"type" : "number",
}
};
This query too many results and sorts on the total number of tweets with the same retweet count. I also cannot figure out why this query doesn't return just the fields specified in the query.
Ideally, the query would return only the fields '['retweetCount', 'favoritesCount', 'preferredUsername', 'body']
This is the query that you should trigger:
curl -X GET 'http://localhost:9200/index_name/type/_search' -d '{
"size" : 25,
"fields" : ["retweetCount", "favoritesCount", "preferredUsername", "body"],
"query": {
"range": {
"postedTime" : {
'gte' : 'now-24M',
'lte' : 'now'
}
}
},
"sort" : {
"retweetCount" : {"order" : "desc"},
"type" : "number",
}
}'
Your are embedding everything inside query hash. This is not needed
I have a combobox on a form where I need to reset its store along with the 'displayField' and 'valueField' configs.
Resetting the store via cmb.bindStore(newStore) works great.
Setting cmb.displayField = 'newfieldname'; also works great.
However, cmb.valueField = 'newValField'; does not work. The combo displays the right stuff, but when i select an item, the value is using the old valueField value, not the new one.
I've tried:
doing a cmb.reset() afterwards
Ext.apply(...)
Is it because valueField is somehow special because it is a required field? Is there some special way to set a config value on an Ext-JS component I don't know about or is it just not possible to change the value of 'valueField'?
FYI - Here is my code:
comp.bindStore(Ext.create('Ext.data.Store', {
fields : [ {
name : 'abbr',
type : 'string'
}, {
name : 'name',
type : 'string'
}, {
name : 'slogan',
type : 'string'
} ],
data : [ {
"abbr" : "AL",
"name" : "Alabama",
"slogan" : "The Heart of Dixie"
}, {
"abbr" : "AK",
"name" : "Alaska",
"slogan" : "The Land of the Midnight Sun"
}, {
"abbr" : "AZ",
"name" : "Arizona",
"slogan" : "The Grand Canyon State"
}, {
"abbr" : "AR",
"name" : "Arkansas",
"slogan" : "The Natural State"
}, ]
}));
comp.displayField = 'abbr'; // THIS WORKS
comp.valueField = 'abbr'; // THIS DOESNT WORK
You are nearly there but you where looking at the wrong property cause valueField is not your issue, it is displayField. Your exact problem are preconfigured and cached properties. The first is the display template the second is the picker instance. You need to override the template and remove the picker instance. Here's a working snipped (JSFiddle)
In the example I added a second trigger with a cross. Hit it and the ComboBox get the new values. I recommend you to create your own component for this by extending from ComboBox and wrap all into a reconfigure method that would expect tree parameters.
Ext.onReady(function() {
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL1", "name":"Alabama1"},
{"abbr":"AK1", "name":"Alaska1"},
{"abbr":"AZ1", "name":"Arizona1"}
//...
]
});
var comp = Ext.create('Ext.form.field.ComboBox', {
fieldLabel: 'Choose State',
id: 'combo-ident',
trigger2Cls: 'x-form-clear-trigger',
onTrigger2Click: function (args) {
var comp = Ext.getCmp('combo-ident');
comp.clearValue();
comp.bindStore(Ext.create('Ext.data.Store', {
fields : [ {
name : 'abbr',
type : 'string'
}, {
name : 'name',
type : 'string'
}, {
name : 'slogan',
type : 'string'
} ],
data : [ {
"abbr" : "AL",
"name" : "Alabama",
"slogan" : "The Heart of Dixie"
}, {
"abbr" : "AK",
"name" : "Alaska",
"slogan" : "The Land of the Midnight Sun"
}, {
"abbr" : "AZ",
"name" : "Arizona",
"slogan" : "The Grand Canyon State"
}, {
"abbr" : "AR",
"name" : "Arkansas",
"slogan" : "The Natural State"
}, ]
}));
comp.displayField = 'abbr';
comp.valueField = 'name';
comp.displayTpl = new Ext.XTemplate(
'<tpl for=".">' +
'{[typeof values === "string" ? values : values["' + comp.displayField + '"]]}' +
'<tpl if="xindex < xcount">' + comp.delimiter + '</tpl>' +
'</tpl>'
);
comp.picker = null;
},
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
});
comp.on('select', function(){ console.log(arguments); console.log(arguments[0].getSubmitValue()); })
});
I am not sure it is possible to reconfigure the combo box this way, but perhaps you can create another combobox with a different store and valueField. Hide/destroy one or the other based on your logic.
I've been writing simple JSON schemas but I ran into an API input call that is a bit more complex. I have one restful end route that can take 3 very different types of JSON:
localhost/foo
can take:
{ "type" : "ice_cream", "cone" : "waffle" ...}
or
{"type" : "hot_dog", "bun" : "wheat" ...}
If the "type" key contains "ice_cream", I only ever want to see the key "cone" and not the key "bun". Similiarly if "type" contains "hot_dog" I only want to see "bun" and not "cone". I know I can pattern match to make sure I only ever see type "ice_cream" or type "hot_dog", but I don't know how to force the requirement of certain other fields if that key is set to that value. I see that there is a json schema field called "dependency" but I haven't found any good examples on how to use it.
BTW, I'm not sure if this input JSON is good form (overloading the type of JSON structure it takes, effectively), but I don't have the option of changing the api.
I finally got some information about this - it turns out you can make a union of several different objects that are valid like so:
{
"description" : "Food",
"type" : [
{
"type" : "object",
"additionalProperties" : false,
"properties" : {
"type" : {
"type" : "string",
"required" : true,
"enum": [
"hot_dog"
]
},
"bun" : {
"type" : "string",
"required" : true
},
"ketchup" : {
"type" : "string",
"required" : true
}
}
},
{
"type" : "object",
"additionalProperties" : false,
"properties" : {
"type" : {
"type" : "string",
"required" : true,
"enum": [
"ice_cream"
]
},
"cone" : {
"type" : "string",
"required" : true
},
"chocolate_sauce" : {
"type" : "string",
"required" : true
}
}
}
]
}
I'm still not sure if this is valid JSON, since my Schemavalidator dies on some invalid input, but it accepts the valid input as expected.