모델을 엠버의 템플릿 컨트롤에 바인딩하려고하는데 성공하지 못했습니다. 먼저 모델을 만든 다음 모델을 컨트롤에 바인딩하려고합니다. 나는 var newCar = sapp.Car.create();
명령으로 차를 만들고있다. 하지만 오류가 발생했습니다템플릿을 컨트롤에 바인딩하기
EmberError: You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.
제 질문은 어떻게 모델을 만들고 템플릿 컨트롤에 바인딩 할 수 있습니까? 아래 코드 샘플은 내가 달성하려는 방식입니다.
예 :
window.sapp = Ember.Application.create();
sapp.Router.map(function() {
this.route("cars");
});
sapp.Car = DS.Model.extend({
plateNumber: DS.attr('string'),
color: DS.attr('string'),
brand: DS.attr('string')
});
컨트롤러
sapp.CarsController = Ember.Controller.extend({
var newCar = sapp.Car.create();
//getting error while creating car
//error:mberError: You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.
});
템플릿 모든
<script type="text/x-handlebars" data-template-name="cars">
<h1>Add Car</h1>
<table>
<tr>
<td>Plate Number</td>
<td>
{{ input value=newCar.plateNumber }}
</td>
</tr>
<tr>
<td>Color</td>
<td>
{{ input value=newCar.color }}
</td>
</tr>
<tr>
<td>Brand</td>
<td>
{{ input value=newCar.brand }}
</td>
</tr>
<tr style="text-align:right">
<td colspan="2">
<button>Add Car</button>
</td>
</tr>
</table>
</script>