在 Ember-cli 中使用 jquery [英] Using jquery in Ember-cli
本文介绍了在 Ember-cli 中使用 jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 Ember.js 和 Ember-cli 都比较陌生,非常感谢在自定义视图中使用 jquery 工具提示的一些帮助.所有代码都在下面,但是当我的模板被注入时,我收到以下控制台错误:
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()')
我在名为 tooltip.js 的文件中使用自定义视图:
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'});
}
});
相关模板代码为:
{{#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?
推荐答案
解决如下:
- jquery 的小部件等不包含在标准 jquery 中ember-cli 使用的库.必须使用
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');
- 正如@Leeft 指出的那样,当从视图或应该使用组件
this.$()
,而不是Ember.$()
- 请务必使用 0.40 之后的 Ember-CLI 版本.
这篇关于在 Ember-cli 中使用 jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文