I have a syntax problem using Actionscript. Can I create new objects from inside an ArrayColletion ?
var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([
{new TagModel("News", 36, yearPopularity, false, true)},
{new TagModel("Information", 18, yearPopularity, false, true)}
]);
This is the error I get:
1084: Syntax error: expecting colon before rightbrace.
thanks
You don't need curly braces when creating objects with new keyword.
var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([
new TagModel("News", 36, yearPopularity, false, true),
new TagModel("Information", 18, yearPopularity, false, true)
]);
Curly braces are for creating objects of type Object
var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([
{tag:"News", x:36, yp:yearPopularity},
{tag:"Information", x:18, yp:yearPopularity}
]);
The following are one and the same:
var a:Object = {value:10};
trace(a.value);//10
var b:Object = new Object();
b.value = 10;
trace(b.value);//10
Related
I'm using ElarsticSearch 7.7 & NEST 7.7 and on my web page, I'm getting 9 search result documents per page. Even I'm showing the first 9 results on the page, I need to return some property values from all the results for side filtration on the web page.
Eg: if I'm searching "LapTop", my page will show 9 results on the first page. Also, I need to show all the "Manufactures" from all the search results. Not only manufacturers in the first-page result. Then customers can filter by manufacture not only display on the first page.
I have tried GlobalAggregation but it returns categories and manufactures only items in selected page.
public SearchResult Search(SearchType searchType, string searchQuery, int storeId, int pageNumber = 1, int pageSize = 12, IList<SearchFilter> requestFilter = null, decimal? priceFrom = 0, decimal? priceTo = 100000000, string sortBy = null, int totalCount = 0)
{
var queryContainer = new QueryContainer();
var sorts = new List<ISort>();
sorts.Add(new FieldSort { Field = "_score", Order = SortOrder.Descending });
switch (sortBy)
{
case "z-a":
sorts.Add(new FieldSort { Field = Field<ElasticIndexGroupProduct>(p => p.SortValue), Order = SortOrder.Descending });
break;
case "a-z":
sorts.Add(new FieldSort { Field = Field<ElasticIndexGroupProduct>(p => p.SortValue), Order = SortOrder.Ascending });
break;
}
var aggrigations = new AggregationDictionary
{
{"average_per_child", new
AverageAggregation("average_per_child",Field<ElasticIndexGroupProduct>(d => d.Price))},
{"max_per_child", new MaxAggregation("max_per_child",Field<ElasticIndexGroupProduct>(d => d.Price))},
{"min_per_child", new MinAggregation("min_per_child", Field<ElasticIndexGroupProduct>(d => d.Price))},
{
"globle_filter_aggrigation", new GlobalAggregation("globle_filter_aggrigation")
{
Aggregations =new AggregationDictionary
{
{"category_flow", new TermsAggregation("category_flow"){Field = Field<ElasticIndexGroupProduct>(p => p.CategoryFlow)} },
{"manufacturers", new TermsAggregation("manufacturers"){Field = Field<ElasticIndexGroupProduct>(p => p.Manufacturer)} }
}
}
}
};
var searchRequest = new SearchRequest<ElasticIndexGroupProduct>()
{
Profile = true,
From = (pageNumber - 1) * pageSize,
Size = pageSize,
Version = true,
Sort = sorts,
//Scroll = Time.MinusOne,
Aggregations = aggrigations
};
var multiMatch = new QueryStringQuery
{
Query = searchQuery,
Fields = GetSearchFields(searchType),
Boost = 1.1,
Name = "named_query",
DefaultOperator = Operator.Or,
Analyzer = "standard",
QuoteAnalyzer = "keyword",
AllowLeadingWildcard = true,
MaximumDeterminizedStates = 2,
Escape = true,
FuzzyPrefixLength = 2,
FuzzyMaxExpansions = 3,
FuzzyRewrite = MultiTermQueryRewrite.ConstantScore,
Rewrite = MultiTermQueryRewrite.ConstantScore,
Fuzziness = Fuzziness.Auto,
TieBreaker = 1,
AnalyzeWildcard = true,
MinimumShouldMatch = 2,
QuoteFieldSuffix = "'",
Lenient = true,
AutoGenerateSynonymsPhraseQuery = false
};
searchRequest.Query = new BoolQuery
{
Must = new QueryContainer[] { multiMatch },
Filter = new QueryContainer[] { queryContainer }
};
var searchResponse = _client.Search<ElasticIndexGroupProduct>(searchRequest);
var categoryFlowsGlobe = new List<string>();
var allAggregations = searchResponse.Aggregations.Global("globle_filter_aggrigation");
var categories = allAggregations.Terms("category_flow");
foreach (var aggItem in categories.Buckets)
{
if (!categoryFlowsGlobe.Any(x => x == aggItem.Key))
{
categoryFlowsGlobe.Add(aggItem.Key);
}
}
}
This is the exact use case for Post filter - to run a search request that returns hits and aggregations, then to apply filtering to the hits after aggregations have been calculated.
For Manufacturers, these can be retrieved with a terms aggregation in the search request - you can adjust the size on the aggregation if you need to return all manufacturers, otherwise you might decide to return only the top x.
I have an animal array:
var animals = [new animal("giraffe", false, 4), new animal("zebra", false, 8), new animal("lion", false, 10), new animal("dog", true, 4), new animal("cat", true, 2)];
How do I pass it to the handlebar and iterate it ? Basically, I want to display all animals, with each of animal, display all of its properties.
Thanks
Minh
I have figured it out myself, in order to do what I want. I need to do:
Server.js:
var animals = [new animal("giraffe", false, 4), new animal("zebra", false, 8), new animal("lion", false, 10), new animal("dog", true, 4), new animal("cat", true, 2)];
// Routes:
app.get("/allpets",function(req,res){
res.render("allpets", {pets: animals});
};
app.get("/pets/:id",function(req,res){
var type = req.params.id;
var index = -1
for(var i = 0; i < animals.length; i++){
if(animals[i].type === type){
index = i;
break;
}
res.render("animal", animals[index]);
});
Then, we will need to create 2 handlebar views. One is called allpets.hbs, the other one is called animal.hbs
allpets.hbs:
<ul>
{{#each pets}}
<li>
<p>Type: {{type}}</p>
<p>Pet: {{pet}}</p>
<p>Fierceness: {{fierceness}}</p>
</li>
{{/each}}
</ul>
============================================================
animal.hbs:
<ul>
<p>Type: {{type}}</p>
<p>Pet: {{pet}}</p>
<p>Fierceness: {{fierceness}}</p>
</ul>
The code below is used to make google-fusion-table work with markercluster together.
(referrence: http://www.cs.gsu.edu/~ashrestha2/vis/prjmap2.html
Give honor to the author very much)
However, when I was trying to follow the example in the above link, I succeed in test 1 but failed in test 2. The test 1 used a fusion table with two columns and the test 2 used a fusion table with three columns. I don't know why I failed as I only added one more column for test 2.
google.load('visualization', '1.0', {"callback":initialize});
//var tableid = '1_6G1c1l7glLHRuOU7uvH8oONbObDf_cOtZS21Rc', atlcenter = new google.maps.LatLng(33.755711,-84.388372); //test1_success
var tableid = '1IagEEylcnbuPygCES70ipnvb9q0C5OgmGPNyx9o1', atlcenter = new google.maps.LatLng(33.755711,-84.388372); //test2_fail
var mapMain, markers, dataTable = null, mc = null;
function initialize() {
mapMain = new google.maps.Map(document.getElementById('map-canvas'), {
center: atlcenter,
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
mc = new MarkerClusterer(mapMain);
queryMap("select * from "+tableid);
}
function queryMap(queryText){
mc.clearMarkers(); markers=[];
var tmp = 'http://www.google.com/fusiontables/gvizdata?tq='+encodeURIComponent(queryText);
var query = new google.visualization.Query(tmp);
query.send(handleQueryResponse);
}
function handleQueryResponse(response){
dataTable = response.getDataTable();
alert(response.isError());
for(var i=0; i< dataTable.getNumberOfRows();i++){
var hrefval = dataTable.getValue(i,0).toString();
var arr = dataTable.getValue(i,1).toString().split(" ");
var latlng = new google.maps.LatLng(arr[0], arr[1]);
var marker = new google.maps.Marker({
position: latlng,
map:mapMain
});
markers.push(marker);
}
mc.addMarkers(markers);
}
This encrypted id is not valid:
1IagEEylcnbuPygCES70ipnvb9q0C5OgmGPNyx9o1
https://www.google.com/fusiontables/DataSource?docid=1IagEEylcnbuPygCES70ipnvb9q0C5OgmGPNyx9o1
I have an ArrayCollection that I'd like to sort by date and then time (in case there's two items with the same date). I've got it sorting by date fine (YYYY/MM/DD) but I can't figure out the time bit, time is in 24 hour format so the code would be basically the same as for the date.
This is the code I used for the date sorting, it works fine.
import mx.collections.SortField;
import mx.collections.Sort;
private function sort():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "date";
var arrayDataSort:Sort = new Sort();
arrayDataSort.fields = [dataSortField];
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
You can use this code to sort by date and time:
private function sort():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "date";
dataSortField.compareFunction = function (a:Object, b:Object) : int {
var na:Number = a.date.getTime();
var nb:Number = b.date.getTime();
if (na < nb)
return -1;
if (na > nb)
return 1;
return 0;
};
var arrayDataSort:Sort = new Sort();
arrayDataSort.fields = [dataSortField];
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
As there are two separate fields that you want to sort on you can just use the Sort object's fields Array to add two sort fields:
var sort:Sort = new Sort();
var fields:Array = [ new SortField("date"), new SortField("time") ];
sort.fields = sort;
linedataColl is an AC that contains 100+ of rows extract from CSV, I wish to add item into SuperDataCollection object by object but the only problem was I'm unable to see any data display in "S" which is a datagrid. What wrong with my code?
var superDataCollection:ArrayCollection = new ArrayCollection();
var dc:ArrayCollection = new ArrayCollection();
var di:Object = new Object();
for(var aa:int=0; aa<5;aa++){
di.username = linedataColl[aa].username;
di.email = linedataColl[aa].email;
dc.addItem(di);
superDataCollection.addItem(dc);
}
s.dataProvider = dc;
For my datagrid:
var columns:Array = [];
var myDataGridColumn:DataGridColumn = new DataGridColumn("id");
myDataGridColumn.headerText = "ID";
myDataGridColumn.width = 40;
columns.push(myDataGridColumn);
... // so on for other column
dg1.columns = columns;
I Found Two thing wrong in your code
1) Declare di in For loop, new instance for each iteration
for(var aa:int=0; aa<5;aa++){
var di:Object = new Object();
2) You are not defining proper dataField for DataGridColumn, although you are passing id in constructor, but i didn't find it in upper code you share,it could be
di.id = aa
or
myDataGridColumn.headerText = "ID";
myDataGridColumn.width = 40;
myDataGridColumn.dataField = "username";
Hopes that helps