javascript - Proper way to get ui element with jquery inside a ItemView Marionette.js - Stack Overflow

I'm learning Marionette.js and would like know the correct way to get the ui element to manipulate

I'm learning Marionette.js and would like know the correct way to get the ui element to manipulate it with jQuery. In my LoginItemView I'm declaring the ui elements and an function to display a error message of invalid login:


ui: {
  username: "#username",
  password: "#password",
  btnLogin: "#btnDoLogin",
  messageContainer: "#messageContainer"
},
displayMessage: function() {
  // show error message
  $(this.ui.messageContainer.selector).show();
},

I also tried:


  $(this.ui.messageContainer[0]).show();

but the message is never displayed.
And here is the code of containerMessage in the template.

<div class="alert alert-danger alert-dismissable login-message-display" id="#messageContainer" style="display: none;">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <strong>Error!</strong> Username and/or password incorrect!
</div>

I'm learning Marionette.js and would like know the correct way to get the ui element to manipulate it with jQuery. In my LoginItemView I'm declaring the ui elements and an function to display a error message of invalid login:


ui: {
  username: "#username",
  password: "#password",
  btnLogin: "#btnDoLogin",
  messageContainer: "#messageContainer"
},
displayMessage: function() {
  // show error message
  $(this.ui.messageContainer.selector).show();
},

I also tried:


  $(this.ui.messageContainer[0]).show();

but the message is never displayed.
And here is the code of containerMessage in the template.

<div class="alert alert-danger alert-dismissable login-message-display" id="#messageContainer" style="display: none;">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <strong>Error!</strong> Username and/or password incorrect!
</div>
Share Improve this question edited Feb 28, 2014 at 5:13 rodrigopandini asked Feb 28, 2014 at 4:24 rodrigopandinirodrigopandini 9451 gold badge8 silver badges18 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

There is no need to add selector on the ui element. ui is a simple object to map the selectors to keys.

Just use

$(this.ui.messageContainer).show();

First of all be sure that you manipulate with DOM elements after view is rendered.

Second - be sure that displayMessage is caled with proper context, i mean this in linked with view instanse.

Third - use this syntax provided by @Billy Chan to operate with node.

If you need further assist - please create fiddle for tests.

It is very Simple to use ui element as jquery object

Use this.ui.messageContainer.show()

this.ui.messageContainer will itself return the jquery object.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744580414a4582001.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信