3
import Ember from 'ember';
export default Ember.TextField.extend({
type: 'text',
didInsertElement: function() {
this.$().addClass("form-control");
var autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')),{types:['geocode']} //trying without jQuery, but still.
);
}});
模板
{{gp-textfield id="autocomplete"}}
这使得以
<input id="autocomplete" type="text" class="ember-view ember-text-field form-control" placeholder="Enter a location" autocomplete="off">
但尽管如此,我得到:
InvalidValueError: not an instance of HTMLInputElement
任何帮助将非常感激。
编辑:余烬2.6
清理代码位,与无济于事
didInsertElement: function() {
this.$().addClass("form-control");
var element = document.getElementById('autocomplete');
var autocomplete = new google.maps.places.Autocomplete(element);
}
不是您的问题的解决方案,但您可以使用类属性[“classNames”](http://emberjs.com/api/classes/Ember.Component.html#property_classNames)指定类的名称零件。它会将它们连接到父类的类名称以及模板中由'class'属性指定的任何类。 – akst
此外,它可能与问题有关,但不是重写didInsertElement,而是建议定义一个新方法,但将其定义为像'Ember.on('didElementInsert',<你的函数>)',它仍然会运行插入但不覆盖父类中的didInsertElement方法,或者您可以在函数的开头调用this._super(arguments),但我感觉前者更加整洁。 – akst
有关覆盖['didInsertElement']的更多信息(https://guides.emberjs.com/v2.6.0/components/the-component-lifecycle/#toc_integrating-with-third-party-libraries-with-code-didinsertelement-代码),更多关于['Ember.on'](http://emberjs.com/api/classes/Function.html#method_on) – akst