在Ember-cli中使用jquery [英] Using jquery in Ember-cli
本文介绍了在Ember-cli中使用jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[错误] TypeError:'undefined '不是一个函数(评估'Ember。$()。tooltip()')
我是在名为tooltip.js的文件中使用自定义视图:
从ember导入Ember;
导出默认值Ember.View.extend({
tagName:'span',
标题:'工具提示标题',
html:true ,
placement:'top',
didInsertElement:function(){
Ember。$()。tooltip({html:this.get('html'),
title:this.get('title'),
placement:this.get('placement'),
container:'body'});
}
});
相关的模板代码是:
{{#viewtooltiptitleBinding =itemplacement =right}}< span>< img class =app_info_iconid =typeInfoIconsrc =/ assets /images/info_icon.png\"></img></span>{{/view}}
如何解决这个问题?
解决方案
解决方法如下:
- Jquery的小部件等不包含在ember-cli使用的标准jquery
库中。必须使用bower install --save jquery-ui
- 然后添加以下行到Brocfile.js :
app.import('bower_components / jquery-ui / jquery-ui.js');
app.import('bower_components / jquery-ui / ui / tooltip.js');
- 确保在0.40之后使用Ember-CLI版本。
< li @ as @Leeft指出,当从视图引用jQuery或
组件
时,应该使用$()
,而不是 Ember $()
I am relatively new to both Ember.js and Ember-cli and would really appreciate some help please with using a jquery tooltip in a custom view. All code is below, but when my template is injected, I get the following console error:
[Error] TypeError: 'undefined' is not a function (evaluating 'Ember.$().tooltip()')
I am using a custom view in a file called tooltip.js:
import Ember from 'ember';
export default Ember.View.extend({
tagName: 'span',
title: 'The tooltip title',
html: true,
placement: 'top',
didInsertElement: function(){
Ember.$().tooltip({"html": this.get('html'),
"title":this.get('title'),
"placement":this.get('placement'),
container: 'body'});
}
});
The relevant template code is:
{{#view "tooltip" titleBinding="item" placement="right"}}<span><img class="app_info_icon" id="typeInfoIcon" src="/assets/images/info_icon.png"></img></span>{{/view}}
How can I fix this please?
解决方案
Solved as follows:
- Jquery's widgets etc. are not included in the standard jquery
library which ember-cli uses. It has to be added using
bower install --save jquery-ui
- You then have to add the following lines to Brocfile.js:
app.import('bower_components/jquery-ui/jquery-ui.js');
app.import('bower_components/jquery-ui/ui/tooltip.js');
- As @Leeft pointed out, when referencing jQuery from a view or
component
this.$()
should be used, notEmber.$()
- Be sure to use a version of Ember-CLI after 0.40.
这篇关于在Ember-cli中使用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文