I have a small problem with my ember app, but I still don't know how to solve it..
I have this error :
Error while loading route: TypeError: Object #<Object> has no method 'addArrayObserver'
With this code :
<script type="text/x-handlebars" data-template-name="enquiry">
{{#link-to 'enquiries' class="create-btn"}}Back to the enquiries{{/link-to}}
<div class="enquiry-info">
<button {{action "update"}}>Update</button>
<table>
<tr>
<td>{{enquiry.customerName}}</td>
</tr>
<tr>
<td>{{customerEmail}}</td>
</tr>
<tr>
<td>{{customerPhone}}</td>
</tr>
</table>
</div>
{{outlet}}
</script>
My controller :
App.EnquiriesController = Ember.ArrayController.extend({
actions: {
clickBtn: function( id ) {
console.log('DEBUG: ClickBtn OK id = ' + id);
this.transitionToRoute('enquiry', id);
}
}
});
Router :
App.EnquiryRoute = Ember.Route.extend({
model: function( param ) {
console.log('Enquiry id = ' + param.enquiry_id);
return App.Enquiries.findOne(param.enquiry_id);
}
});
To explain this better, I have a button, and when the user click on it, it trigger the clickBtn function. That return in my router the content of an ajax call from my server.
The thing is that is return me an object and it seems that ember prefer to have an array no ?
Is it possible to display an object in the template instead ?
Here is the ajax call :
findOne: function(id) {
var result = {};
$.ajax({
url: host + 'mdf/enquiry/' + id,
type: 'GET',
accepts: 'application/json',
success: function (data) {
result = data;
},
error: function() {
console.log('DEBUG: GET Enquiry ' + id + ' Failed');
}
});
return result;
}
Thanks for the help !! :)
[edit]
My router map :
App.Router.map(function() {
this.resource('login', { path: '/' });
this.resource('home');
this.resource('enquiries', function (){
this.route('create');
});
this.resource('enquiry', { path: '/:enquiry_id' }, function(){
this.route('update');
});
});
This is the object I've back from the server :
Object {ok: true, enquiry: Object}
enquiry: Object
-createdAt: "2014-02-03T15:32:16.000Z"
-customerEmail: "[email protected]"
-customerName: "Name Test"
-customerPhone: "01523456789"
-id: 1
-__proto__: Object
ok: true
__proto__: Object