मैंने एम्बर डेटा के बिना कई मॉडल काम करने और बनाने के लिए एक छोटा सा उदाहरण बनाया।एम्बर जेएस (एम्बर डेटा के बिना) में आप कई मॉडलों के साथ कैसे काम करते हैं?
App = Ember.Application.create();
App.Router.map(function() {
this.resource('employees', function() {
this.route('employee');
});
});
App.Employee = Ember.Object.extend({});
App.Employee.reopenClass({
findAll: function() {
return $.getJSON("http://localhost/api/employee").then(
function (response) {
var employees = [];
response.forEach(function (child) {
employees.push(App.Employee.create(child));
});
console.log(employees.join('\n'));
return employees;
}
);
}
});
App.EmployeesController = Ember.ArrayController.extend({});
App.EmployeesRoute = Ember.Route.extend({
model: function() {
return App.Employee.findAll();
}
});
Handlebars:
<script type="text/x-handlebars">
<p>Application template</p>
{{#linkTo employees}}<button>Show employees</button>{{/linkTo}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="employees">
<p>Employees template</p>
{{#each controller}}
<p>{{Name}}</p>
{{/each}}
{{outlet}}
</script>
जब मैं सीधे localhost/#/employee
url पर नेविगेट, यह पूरी तरह से ठीक काम करता है, लेकिन जब मैं "कर्मचारियों शो" बटन पर क्लिक करें, मैं निम्नलिखित त्रुटि मिलती है:
Uncaught TypeError: Object #<Object> has no method 'addArrayObserver'
मुझे शायद कहीं कुछ याद आ रहा है, लेकिन मुझे बिल्कुल यकीन नहीं है कि त्रुटि किस वस्तु का जिक्र कर रही है। जब मैं बटन दबाता हूं तो मेरा मॉडल हुक सही ढंग से बुलाया जा रहा है, जैसा कि मैंने मैन्युअल रूप से यूआरएल इनपुट करके नेविगेट किया है, इसलिए मुझे समझ में नहीं आता कि दो मामलों में वास्तव में क्या अलग है।