Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

ember.js - Using jquery in Ember-cli

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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, not Ember.$()
  • Be sure to use a version of Ember-CLI after 0.40.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...