NGX-charts bubble chart how to reload displayed data - javascript

I have a bubble chart (using it as a scatter plot but whatever) from ngx-charts. The HTML is set up so that as the user clicks on an element of the page the contents of the chart change based on the updateTitleData() function. In testing however as I click on the elements the data of the scatterData array changes however this does not change the actual displayed chart. So my question is how to get the chart to dynamically reload while running.
I have read a bit about it online, people have said that you need to change the actual scatterData array rather than just the "series" element of it which I tried by making an array value in updateTitleData that held the whole array and then jut doing this.scatterData=newData; at the end of the function which again did set the data correctly but still didn't cause the chart to update.
I also read that you need to put a [update$]="update$" in the html code and then when defining the chart variables in the typescript code use update$: Subject<any> = new Subject(); followed by defining the function updateChart(){ this.update$.next(true); } so that you can just call updateChart() whenever you need the chart to update. I tried that however it would just throw an error while loading initially due to the [update$]="update$" element being included in its constructor.
public scatterData = [{
"name" : "LQArray",
"series" : [{
"name" : "a",
"x" : 1,
"y" : 2,
"r" : 1
}]
}];
private updateTitleData() {
if(this.regionData && this.regionData.location_quotient){
this.scatterData["series"] = [];
this.jobTitles.forEach((value) => {
var newScatterData = [{
"name":value,
"x":parseFloat(this.regionData.x_axis[value]),
"y":parseInt(this.regionData.y_axis[value]),
"r":1
}];
this.scatterData["series"].push(newScatterData);
});
}
}
Here is the code in question. The chart does display the "a" element that is defined at the beginning, but that should be deleted and replaced as soon as the element is clicked.

I figured it out.
I was populating the "series" element incorrectly.
What I had:
this.jobTitles.forEach((value) => {
var newScatterData = [{
"name":value
"x":parseFloat(this.regionData.x_axis[value]),
"y":parseInt(this.regionData.y_axis[value]),
"r":1
}];
this.scatterData["series"].push(newScatterData);
});
What I needed:
this.jobTitles.forEach((value) => {
var newScatterData = {
"name":value
"x":parseFloat(this.regionData.x_axis[value]),
"y":parseInt(this.regionData.y_axis[value]),
"r":1
};
this.scatterData[0]["series"].push(newScatterData);
});
this.scatterData=[...this.scatterData];
Basically needed the [0] in front of the ["series"] and needed to remove the array element from newScatterData.

Related

Mix clickable row and unclickable row on slickgrid

For my columns definition.
var columns = [
{id: "label", name: "point", formatter:this.clickableFormatter,field: "point",width: 150},
then I add clickhander for it.
chart.addClickHandler(){
}
Also I use clickableFormatter for this.
clickableFormatter(row,cell,value,columnDef,dataContext){
return "<span style='cursor:pointer;'>" + value + "</span>";
}
From these code. my table rows are clickable and I can show the user where is clickable by changing pointer.
However now I want to make one row unclickable.
(for example total row)
Is it possible to prevent click event for one low??
And is it possible to use another formatter for one row?
I gave the data from for loop and add total seperately.
for (var k = 0 ; k < data.length ;k++){
var temp = new Array();
temp['id'] = data[k]['id'];
temp['point'] = data[k]['point'];
ret.push(temp);
}
ret.push({
'id' : "total",
"point" : pointTotal,
});
In your formatter, you have access to the value of the cell, so if value==='total', just return an empty string.
Also FYI, I don't think you need the for loop in your code (you could just leave it out entirely), unless you're using it to calculate the total, but you don't seem to be doing that.
If you think that you need it for creating the array objects, you're misunderstanding arrays in javascript, what you're actually setting is object properties, and it would be usual to initialise with var temp = { }; rather than as Array.
It may not make sense at first, but everything in javascript is an object, including arrays and functions. So you can add object properties to anything.
somevar[numericVal] = x; // set array element, somevar must be type Array
somevar['stringVal'] = x; // set object property 'stringVal'
somevar.stringVal = x; // identical to above line, different way of specifying

dgrid not showing all rows in the store

I have a data array with 165 elements, and I am showing them in an OnDemandGrid, sorted by a date field. However, when the grid shows up, only the last 140 elements in the data array are shown (i.e., the elements with the 140 most recent dates). Still, if I click the date header to reverse the sort, the first 140 elements show (i.e., the elements with the 140 oldest dates). So my guess is that somehow the mechanism of lazy loading is not working, still I don't get why only the last portion of the array is shown instead of the first. I am not using pagination, nor I set other options related to the size. Any suggestion?
The grid is added to a div which is already in the page:
<div id="navList" class="dgrid-autoheight"></div>
Here's the code for the grid, below you can find the data array:
function fillNavList(data) {
var columns =
[
{
field : "date",
label : L["date"]
},
{
field : "value",
label : L["value"]
},
{
field : "dateModification",
label : L["dateModification"]
},
{
field : "status",
label : L["status"]
},
{
field : "valueRefId",
label : L["valueRefId"]
}
];
require(
[
"dojo/on",
"dstore/Memory",
"dstore/Filter",
"dgrid/OnDemandGrid",
"dojo/_base/declare"
], function(on, Memory, Filter, OnDemandGrid, declare) {
var store = new Memory({
data : data
});
var navList = new (declare(
[
OnDemandGrid
]))({
columns : columns,
sort: "date",
collection : store,
addUiClasses : false
}, "navList");
});
}
And here's the data:
[{"date":"2000-01-31","value":96.02,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-02-28","value":100,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-03-29","value":92.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-04-30","value":93.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-05-31","value":100.25,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-06-28","value":107.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-07-31","value":114.06,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-08-30","value":120.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-09-30","value":126.43,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-10-31","value":116.66,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-11-29","value":110.73,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-12-31","value":119.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-01-31","value":135.13,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-02-28","value":144.88,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-03-31","value":126.29,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-04-30","value":128.12,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-05-30","value":137.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-06-30","value":127.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-07-31","value":119.34,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-08-29","value":119.42,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-09-30","value":127.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-10-31","value":146.88,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-11-28","value":146.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-12-31","value":154.32,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-01-30","value":160.79,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-02-27","value":174.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-03-31","value":178.51,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-04-30","value":157.99,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-05-31","value":146.95,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-06-30","value":145.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-07-30","value":145.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-08-31","value":136.25,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-09-30","value":146.82,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-10-29","value":147.94,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-11-30","value":162.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-12-31","value":154.17,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-01-31","value":147.57,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-02-28","value":148.36,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-03-31","value":151.77,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-04-29","value":137.69,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-05-31","value":132.07,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-06-30","value":139.09,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-07-27","value":148.3,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-08-31","value":152.43,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-09-30","value":173.12,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-10-31","value":163.36,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-11-30","value":188.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-12-30","value":204.03,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-01-31","value":226.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-02-28","value":220.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-03-31","value":249.33,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-04-28","value":277.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-05-31","value":266.03,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-06-30","value":249.8,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-07-31","value":236.82,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-08-31","value":241.44,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-09-29","value":243.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-10-06","value":243,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-10-31","value":243.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-11-30","value":244.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-12-29","value":248.81,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-01-31","value":250.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-02-28","value":237.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-03-30","value":216.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-04-30","value":221.92,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-05-31","value":232.35,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-06-29","value":243.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-07-31","value":202.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-08-31","value":163.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-09-28","value":169.58,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-10-31","value":192.84,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-11-30","value":176.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-12-31","value":191.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-01-31","value":232.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-02-29","value":299.72,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-03-31","value":275.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-04-30","value":252.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-05-30","value":265.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-06-30","value":288.32,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-07-31","value":234.16,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-08-29","value":218.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-09-30","value":243.7,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-10-31","value":354.57,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-11-28","value":379.28,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-12-31","value":399.38,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-01-30","value":405.77,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-02-27","value":405.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-03-31","value":392.02,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-04-30","value":370.42,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-05-29","value":365.6,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-06-30","value":340.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-07-31","value":338.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-08-31","value":375.67,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-09-30","value":380.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-10-30","value":350.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-11-30","value":388.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-12-31","value":375.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-01-29","value":361.39,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-02-26","value":335.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-03-10","value":318.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-03-31","value":318.16,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-04-30","value":324.68,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-05-28","value":296.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-05-31","value":296.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-06-30","value":297.78,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-07-30","value":261.96,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-08-31","value":300.18,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-09-30","value":349.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-10-29","value":427.49,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-11-30","value":404.6,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-12-31","value":506.97,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-01-31","value":517.49,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-02-28","value":567.69,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-03-31","value":541.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-04-29","value":574.72,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-05-31","value":506.78,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-06-30","value":469.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-07-29","value":521.53,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-08-31","value":529.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-09-30","value":507.55,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-10-31","value":435.8,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-11-30","value":488.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-12-30","value":480.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-01-31","value":462.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-02-29","value":465.92,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-03-30","value":490.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-04-30","value":484.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-05-31","value":480.55,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-06-29","value":393.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-07-31","value":438.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-08-31","value":410.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-09-28","value":375.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-10-31","value":319.01,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-11-30","value":315.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-12-31","value":318.33,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-01-31","value":351.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-02-28","value":377.62,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-03-29","value":412.7,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-04-30","value":452.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-05-31","value":453.45,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-06-28","value":439.18,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-07-31","value":421.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-08-30","value":375.51,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-09-30","value":385.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-10-31","value":413.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-11-29","value":461.28,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-12-31","value":455.58,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-01-31","value":448.93,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-02-28","value":455.05,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-03-31","value":476.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-04-30","value":488.89,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-05-30","value":467.05,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-06-30","value":478.1,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-07-31","value":488.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-08-29","value":534.46,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-09-30","value":629.01,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-10-31","value":618.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-11-28","value":699.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-12-31","value":762.46,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-01-30","value":815.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-02-27","value":811.23,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-03-31","value":842.4,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-04-30","value":775.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-05-29","value":807.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-06-30","value":758.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0}]
Thanks in advance
Found it! Turns out my data elements did not have an id attribute, and this is somehow messing up the grid's ability to render the rows. I found a pointer to the solution in https://github.com/SitePen/dstore/blob/master/docs/Stores.md where it says:
The data should be an array of objects, and all the objects are considered to be existing objects and must have identities
After adding a unique identifier to my data, everything works ok.

Changing an array of objects structure in Javascript for Sencha Touch Ext.ux.TouchCalendar

I'm building a Sencha Touch app that utilizes the awesome calendar plugin https://github.com/SwarmOnline/Ext.ux.TouchCalendar , however, some custom implementation is needed in order to utilize the events functionality.
I've already tied the events template to a store, which fetches data from the server. It works as planned, but the problem is the plugin looks for ALL records in the store and counts each one as an event (because in the event model, it looks for "date" as the start and end point). So every day looks like has an event, even though those without "items" are blank, see: http://cl.ly/image/3j461O2L2Y1k. I only want to display events with "items"
My data from the server that comes back in the following format (many days do not have "items"):
[
{
"day":28,
"iscurrentmonth":false,
"issunday":false,
"date":"2013-05-28",
"items":[
{
"id":134513,
"title":"Subject",
"typeid":3,
"typename":"Essay",
"author":"Bryan Fisher",
"classname":"English 9A",
"classid":344499,
"courseid":60555
},
{
"id":134485,
"title":"Subject",
"typeid":3,
"typename":"Essay",
"author":"Bryan Fisher",
"classname":"English 10",
"classid":344500,
"courseid":60555
}
]
}
]
So, I have to change the data array's structure into the following format:
[
{
"date":"2013-05-28",
"id":134513,
"title":"Subject",
"typeid":3,
"typename":"Essay",
"author":"Bryan Fisher",
"classname":"English 9A",
"classid":344499
},
{
"date":"2013-05-28",
"id":134485,
"title":"Subject",
"typeid":3,
"typename":"Essay",
"author":"Bryan Fisher",
"classname":"English 10",
"classid":344500
}
]
How can I change the original object to match the new format? (take the "date" and insert it into the "items" node) ?
I am completely open to something like underscore.js
Thanks in advance
Maybe I over thought this whole thing...
A bit of a hack...
in TouchCalendarEvents.js I added the following method to check for an empty event div
hideOthers: function(){
var bar = $('.event-bar');
for (var i = 0; i < bar.length; i++){
var allBars = bar[i];
if (allBars.innerHTML == ''){
console.log('number ' + i + 'is Empty!' );
allBars.remove();
}
}
},
and call it in refreshEvents
refreshEvents: function(){
// scroll the parent calendar to the top so we're calculating positions from the base line.
if(this.calendar.getScrollable()){
this.calendar.getScrollable().getScroller().scrollTo(0,0);
}
this.removeEvents();
this.getViewModeProcessor().generateEventBars(); // in turn calls this.renderEventBars(this.eventBarStore);
this.createEventWrapper();
this.hideOthers();
if (this.getAllowEventDragAndDrop()) {
this.createDroppableRegion();
}
},
Works well enough for now!

Changing nested attribute with model.set in Backbone

I'm trying to do what I hope is a simple thing -- doing a model.set only on a sub attribute of the object.
Right now, I have a model that looks like this:
{
"attr1" : true,
"attr2" : this.model.get("username"),
"attr3" : $('#tenant_select').val(),
"attr_array": [
{
"id": "sub_1",
"state": "active"
},
{
"id": "sub_22",
"state": "not_active"
}
]
}
I want to be able to grab reach into myMode.attr_array.state and change the value. However, using .set I've only been able to change attributes on the first level, i.e. attr_array.
Is there an way to do this using model.set?
You can do it (I'm wondering why you didn't manage to do it). But you have to be careful:
var array = this.get('attr_array');
array[1].state = 'active';
this.set('attr_array', array);
What's the problem here? Your model holds a reference of the object. Therefore the last line is useless, it won't change anything at all. It's simply equivalent to:
this.get('attr_array')[1].state = 'active';
And you lose any internal stuff Backbone does when you use set.
So what to do? Clone your object:
var array = _.clone(this.get('attr_array'));
array[1].state = 'active';
this.set('attr_array', array); // will trigger 'change' and 'change:attr_array' events

How to create an array in jQuery for holding values of each post?

What I want to do is set an icon for each category using jQuery. So far the code looks like this:
var category = $(".odd, .even").children('.views-field-field-category').text();
if (category=="funny") {
$(".odd, .even").children('.views-field-field-category').html('image-tag');
}
Since the variable category gathers all of the category values in that page and combines them (so that it looks like "funny gifs videos gifs" etc) I've decided that I need an array to hold them each seperately. Now I've tried to do it in various ways, but without any success. Can you please help and show me how to set it up so that I could use if (category[i]=="funny") { do this }?
You can create an object:
var o = {
'funny' : 'html-tag',
'gifs' : 'html-tag2',
'crazy' : '...'
}
And use html callback function.
$(".odd, .even").children('.views-field-field-category').html(function(i, html){
var prop = $(this).text().toLowerCase();
return o[prop];
})

Categories

Resources