I need inser data from model to dataTables "aaData:". I can't get objects from store at normal array, but as DS.RecordArray and what next? Console command to get some properties of some object is following command :
var dev = App.Model.Store.find("model")
dev.content.content[1]._data.someProperty
I don't know how to get this object or his property at javascript.
Please, help :)
With Ember Data beta 1 or later you'd do this in a controller or route.
var dev = this.store.find("model");
// dev is a promise that will be resolved when/if
// the collection is actually loaded
dev.then(function(realDev){
// at this point realDev is a DS.RecordArray
// you could turn it into a real array by cally .toArray()
var devAry = realDev.toArray();
// then you can call get() on an item to retrieve a property
var someProp = devAry[1].get('someProperty');
});
Related
I have the following lines in my SAPUI5 app
var dateVal = controls.awardDate.getDateValue();
var month = dateVal.getMonth();
awardDate is a datepicker the user enters a date on and returns a javascript date object. This is a snippet of my qunit to test this element.
awardDate: {
getValue: getInvalidValue,
getValueState: getValueStateWarning,
setValue: setValue,
getDatevalue: getDateValue
}
In my qunit I get an error saying that the object doesn't support property or method 'getDateValue'. I'm not sure how I'm supposed to stub this function when it returns an object. Other tests I have do it this way
var getValue = sinon.stub().returns('');
where I get an empty string.
so my attempt at to do it with the datepicker is
var getDateValue = sinon.stub().returns(new Date());
but this doesn't work. I still get the same error. Has anyone done this before?
edit/update: I was able to fix part of the problem by doing the following
var getValueDate = sinon.stub().returns(Object, function(){ });
Now the problem I have is the same error but for getMonth() which returns a string. All other variables are global but dateVal is created on the spot when the user updates the datepicker. Any ideas on how to proceed on this one?
Try with this code:
var getValueDate = sinon.stub(controls.awardDate, 'getDateValue');
var month = {
getMonth: sinon.stub()
}
getValueDate.returns([month]);
I was able to figure out how to solve this. I had to make the Object type a specific Date object like this
var getValueDate = sinon.stub().returns(new Date()), function(){ });
I'm using ember v1.10 and ember data v1.0.0-beta.15 on an existing project. I have a service that returns an object that has a message string and an array of publishable ids. As follows:
data: [{"Message":"Example 1 cannot be published the following items to be published",
"PublisherIds":[
"b9b77872-6954-404f-b451-b5a1938b2fa8",
"030b39de-5746-4ed4-9e17-e86bb49be164"]
},
{"Message":"Example 2 cannot be published items to be published",
"PublisherIds":[
"b9b77872-6954-404f-b451-b5a1938b2fa8",
"030b39de-5746-4ed4-9e17-e86bb49be164"]
}]
In my controller, I want to iterate through the publisher ids and use them to get all the other data associated with the items from the model called 'publishable' that is already in my store and push them in to an array so I can display them in a table in my template.
My attempt:
var _this = this;
data.forEach(function(d){
var items = [];
d.PublisherIds.forEach(function(a){
var temp = _this.store.find('publishable', a);
d.items.push(temp);
});
} );
Unfortunately the store.find doesn't seem to work. I'm not getting the actual records and I can't push them into an array. Any help is appreciated!
I see this question is being ask all over again still don't find solution that works for such a trivial task.
This url displays a list of navigations tabs for workspaces.
http://localhost:4200/users/1/workspaces
Each of tab resolves to
http://localhost:4200/users/1/workspaces/:wid
Also on the I have a button that suppose to create a new workspace as well as new tab.
Here how controller for looks:
export default Ember.Controller.extend({
actions: {
newWorkspace: function () {
this.get('currentModel').reload();
var self = this;
var onFail = function() {
// deal with the failure here
};
var onSuccess = function(workspace) {
self.transitionToRoute('dashboard.workspaces.workspace', workspace.id);
};
this.store.createRecord('workspace', {
title: 'Rails is Omakase'
}).save().then(onSuccess, onFail);
}
}
});
When I click on button I see in ember inspector new record indeed created as well as url redirected to id that represents newly created workspace.
My question is how to force model/template to reload. I have already killed 5h trying model.reload() etc. Everything seem not supported no longer. Please please help.
UPDATE
When adding onSuccess
model.pushObject(post);
throws Uncaught TypeError: internalModel.getRecord is not a function
I believe you should call this.store.find('workspace', workspace.id) for Ember Data 1.12.x or earlier. For 1.13 and 2.0 there are more complicated hooks that determine whether or not the browser should query the server again or use a cached value; in that case, call this.store.findRecord('workspace', workspace.id, { reload: true }).
I do not know if this help. I had a similar problem. My action was performed in the route. Refresh function took care of everything.
I am writing an Ember-Data adapter for the Rhom API. I have written the code. I am using it in a simple Todo App. When I create a new item, it gets into the SQLite db. But when I start the app, the already existing ones donot get loaded in the store.
I wrote a console.log in the findAll of my adapter and I can see that it gets an object array from the Rhom API and returns a promise with those results. But why does it not load into the store?
I used the localstorage-adapter as an example and did this. Here is my findAll:
extractVars: function(rhomRecord) {
return rhomRecord.vars();
},
sourceIdToId: function(record) {
record["id"] = record.source_id;
return record;
},
findAll: function(store, type) {
var records = Rho.ORM.getModel(this.model).find('all');
var results = records.map(this.extractVars);
var results = results.map(this.sourceIdToId);
console.log(results);
return Ember.RSVP.resolve(results);
},
As you can see, the console.log prints the following out and its just an array of objects that contain what I need. When I tried with the locastorate, it also returned a same kind of objects.
What do I do?
PS: The extractVars and sourceIdtoId are auxillary to propery extract the objects from the records returned by Rhom.
I'm not really sure if this will help you but I guess just because .find() returns a promise you should use the .then() callback to resolve your model:
findAll: function(store, type) {
return Rho.ORM.getModel(this.model).find('all').then(function(records) {
var results = records.map(this.extractVars);
var results = results.map(this.sourceIdToId);
console.log(results);
return Ember.RSVP.resolve(results);
});
}
Hope it helps.
I know how to update and redraw a jqPlot object without using ember...
I created the following fiddle to show the "problem": http://jsfiddle.net/QNGWU/
Here, the function load() of App.graphStateController is called every second and updates the series data in the controller's content.
First problem: The updates of the series seem not to propagate to the view.
Second problem: Even if they would, where can i place a call to update the plot (i.e. plotObj.drawSeries())?
I already tried to register an observer in the view's didInsertElement function:
didInsertElement : function() {
var me = this;
me._super();
me.plotObj = $.jqplot('theegraph', this.series, this.options);
me.plotObj.draw();
me.addObserver('series', me.seriesChanged);
},
seriesChanged: function() {
var me = this;
if (me.plotObj != null) {
me.plotObj.drawSeries({});
}
}
But that didn't work...
Well, figured it out, see updated fiddle.
The secret sauce was to update the whole graphState object (not just it's properties) in App.graphStateController:
var newState = App.GraphState.create();
newState.set('series', series);
me.set('content', newState);
And then attach an observer to it in the App.graphStateView:
updateGraph : function() {
[...]
}.observes('graphState')
The updateGraph function then isn't pretty, since jqPlot's data series are stored as [x,y] pairs.
The whole problem, i guess, was that the properties series and options in the App.graphState object itself are not derived from Ember.object and therefore no events are fired for them. Another solution may be to change that to Ember.objects, too.