I’m new to Ember. Is there a way to initialize and bind Javascript UI Widgets like Wijmo or KendoUI?
I’ve tried to observe the model and update the Wijmo Flexgrid by hand but didn’t get it to work.
This is what i got so far:
export default Ember.Controller.extend({
queryParams: ['firstname', 'lastname', 'street', 'zip', 'region', 'city', 'mobile', 'landline'],
model: {},
currentPathDidChange: function() {
Ember.run.schedule('afterRender', this, function() {
// create the grid and give it some data
var grid = new wijmo.grid.FlexGrid('#gsFlexGrid');
this.set('grid', grid);
//
return true; // Bubble the didTransition event
});
}.observes('currentPath'),
dependency: function() {
console.log('the model has changed');
var grid = this.get('grid'); // this doesn't deliver the grid i want to have!!!
var entries = [];
this.get('model').forEach(function (entry){
entries.push(entry);
});
console.log(entries); //some proxy objects and not the main entity!
grid.itemsSource = entries; //doesn't work!
}.observes('model')
});
Hm, in that case, the willRender hook is not appropriate as it runs everytime and binding changes. We need to modify it.
export default Ember.Component.extend({
didInsertElement() {
var grid = new wijmo.grid.FlexGrid(this.get('element')); // Ember.Component already have an element you can use
this.set('grid', grid);
},
didRender() { // runs every time an attribute changes
var grid = this.get('grid');
// do things with grid
}
});
now I habe my component which I’m passing in the model. But how can i get the Model data as an Array?
{{#wijmo-grid gridData=model}}{{/wijmo-grid}}
export default Ember.Component.extend({
gridData: [],
didInsertElement() {
var grid = new wijmo.grid.FlexGrid(this.get('element')); // Ember.Component already have an element you can use
this.set('grid', grid);
},
didRender() { // runs every time an attribute changes
var grid = this.get('grid');
console.log(this.get('gridData'));
grid.itemsSource = this.get('gridData'); //how can i get the Model data as an Array?
}
});
What do you mean by getting the model data as an array? What is it exactly? You can get any Ember Object’s class name by converting it to a string, like this console.log(String(obj))
Data for the Wijmo FlexGrid has to be in this form: [{col1:data1, col2:data2},{col1:data3, col2:data4}].
So if i pass in the model with {{#wijmo-grid gridData=model}} I’ve got the whole model in the component. So i need to extract the data out of the model somehow.
I need something like {{#each model as |post|}} only in Javascript
That is correct. You can create a Ember.ComputedProperty on the component that watches change on model. If appropriate, you can even use Ember.computed.map to map over the model with something different.