Ember.js EmberJs:在init函数中绑定Ember.TextField中的输入元素(自动完成谷歌地图)
我尝试使用谷歌地图自动完成组件。 这个GoogleJavaScript服务只需要绑定到一个输入字段 我的想法是创建一个新的视图扩展TextField,并按照下面所述进行绑定: 我对自动完成构造函数(此选项)中的“this”有疑问。 正如你很容易理解的,这是我的输入组件。。。(错误可能就在这里) 以及html代码模板:Ember.js EmberJs:在init函数中绑定Ember.TextField中的输入元素(自动完成谷歌地图),ember.js,Ember.js,我尝试使用谷歌地图自动完成组件。 这个GoogleJavaScript服务只需要绑定到一个输入字段 我的想法是创建一个新的视图扩展TextField,并按照下面所述进行绑定: 我对自动完成构造函数(此选项)中的“this”有疑问。 正如你很容易理解的,这是我的输入组件。。。(错误可能就在这里) 以及html代码模板: {{view App.AutoCompleAddressView}} 不幸的是,我得到了一个余烬错误: 未捕获类型错误:对象没有方法“getAttribute”如果google.
{{view App.AutoCompleAddressView}}
不幸的是,我得到了一个余烬错误:
未捕获类型错误:对象没有方法“getAttribute”如果google.maps.places.Autocomplete需要DOM元素,则必须将此。$()传递给它。我想你必须在didInsertElement钩子里这样做。比如:
App.AutoCompleAddressView = Ember.TextField.extend({
type: 'text',
didInsertElement: function() {
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};
//this.$() return the element as an array form, but google autocomplete seems to not accept this. So take the first one.
new google.maps.places.Autocomplete(this.$()[0], options);
}
});
添加了一个最小的示例:相同的错误:未捕获的类型错误:对象[Object Object]没有方法'getAttribute'YJ.$l(匿名函数)(匿名函数)%7Bmain,places%7D.js:9(匿名函数)%7Bmain,places%7D.js:24 O%7Bmain,places%7D.js:9 wf,但我发现了这篇文章(我不完全理解):更新的答案,似乎您必须从jquery选择器中获取第一个元素
App.AutoCompleAddressView = Ember.TextField.extend({
type: 'text',
didInsertElement: function() {
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};
//this.$() return the element as an array form, but google autocomplete seems to not accept this. So take the first one.
new google.maps.places.Autocomplete(this.$()[0], options);
}
});