javascript - Ember.TextField : Access to jquery object -
my first post on stackoverflow. (and english not native tongue).
i trying learn how use emberjs. it's not easy because of lack of tutorials.
so decided code chat, use nodejs , socket.io server-side.
html
<script type="text/x-handlebars"> <div class="page"> <div class="users"> </div> <div class="messagebox"> {{#view app.textfield valuebinding="currentmsg" placeholder="your message"}}{{/view}} <button {{action "sendmsg"}}>send</button> </div> <div id="chatbox"> {{#collection contentbinding="app.msgscontroller" tagname="ul"}} <b>{{value}}</b> {{/collection}} </div> </div> </script>
javascript
var id; var socketio = io.connect("127.0.0.1:8888"); socketio.on('id', function (data) { id = data; }); socketio.on("broadcast", function (data) { if (id == data.id) { return } app.msgscontroller.addmsg(data.message); }); socketio.on("own", function (data) { app.msgscontroller.addmsg(data.message); }); app = ember.application.create(); app.msg = ember.object.extend({ value: null }); app.msgscontroller = ember.arraycontroller.create({ content: [], addmsg: function (value) { var msg = app.msg.create({ value: value }); this.pushobject(msg); } }); app.textfield = ember.textfield.extend({ insertnewline: function() { this.get("controller").send("sendmsg"); } }); app.applicationcontroller = ember.controller.extend({ currentmsg: 't', sendmsg: function () { var currentmsg = this.get('currentmsg'); if(currentmsg) { socketio.emit("message", { message: currentmsg, id: id}); this.set('currentmsg', ''); } } });
i want focus app.textfield after app.applicationcontroller.sendmsg call.
i tried
app.textfield.$().focus()
but seems can use $() inside of methods.
someone can me, please?
edit : ok, found answer.
app.textfield "class", , 1 on view instance.
i must add id in view
{{#view app.textfield valuebinding="currentmsg" placeholder="your message" id="mytextfield"}}{{/view}}
and use jquery selector access instance
$('#mytextfield').focus();
use didinsertelement hook view handle jquery methods.
http://emberjs.com/api/classes/ember.view.html#event_didinsertelement
Comments
Post a Comment