我想知道在 Ember 中是否有一些好的方法来重组这个烂摊子!
如您所见,我有两个 TextField 的代码几乎相同!
我讨厌在我的页面中有相同的代码,我希望你能给我一些提示来改进我在 Ember 中的编程风格。
var App = Ember.Application.create();
App.ApplicationView = Ember.View.extend({});
App.StationsDepController = Ember.ArrayController.create();
App.StationsArrController = Ember.ArrayController.create();
App.ResultsController = Ember.ArrayController.create();
App.DepartureTextValue = Em.Object.create({
value: ''
});
App.ArrivalTextValue = Em.Object.create({
value: ''
});
App.DepartureTextField = Em.TextField.extend({
attributeBindings: ['list'],
list: 'datalistDep',
valueBinding: 'App.DepartureTextValue.value',
textValue: App.DepartureTextValue,
placeholder: 'Departure',
arrayCtrl: App.StationsDepController,
keyUp: function(e) {
var that = this;
if (this.textValue.get('value') != '') {
$.get('/metier/services/rest/StationSI/Stations?letters=' + this.textValue.value, function(data) {
that.arrayCtrl.set('content', data);
});
} else {
this.arrayCtrl.set('content', '');
}
}
});
App.ArrivalTextField = Em.TextField.extend({
attributeBindings: ['list'],
list: 'datalistArr',
valueBinding: 'App.ArrivalTextValue.value',
textValue: App.ArrivalTextValue,
placeholder: 'Arrival',
arrayCtrl: App.StationsArrController,
keyUp: function(e) {
var that = this;
if (this.textValue.get('value') != '') {
$.get('/metier/services/rest/StationSI/Stations?letters=' + this.textValue.value, function(data) {
that.arrayCtrl.set('content', data);
});
} else {
this.arrayCtrl.set('content', '');
}
}
});