Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ember.TextField:访问jquery对象_Javascript_Jquery_Ember.js - Fatal编程技术网

Javascript Ember.TextField:访问jquery对象

Javascript Ember.TextField:访问jquery对象,javascript,jquery,ember.js,Javascript,Jquery,Ember.js,我在stackoverflow上的第一篇文章。(英语不是我的母语) 我正在努力学习如何使用emberjs。 这并不容易,因为缺少好的教程 所以我决定编写一个聊天代码,我使用nodejs和socket.io服务器端 Html {{{#view App.TextField valueBinding=“currentMsg”placeholder=“your message”}{{{/view}} 发送 {{{#collection contentBinding=“App.MsgsControlle

我在stackoverflow上的第一篇文章。(英语不是我的母语)

我正在努力学习如何使用emberjs。 这并不容易,因为缺少好的教程

所以我决定编写一个聊天代码,我使用nodejs和socket.io服务器端

Html


{{{#view App.TextField valueBinding=“currentMsg”placeholder=“your message”}{{{/view}}
发送
{{{#collection contentBinding=“App.MsgsController”tagName=“ul”}
{{value}}
{{/collection}
Javascript

var-id;
var socketio=io.connect(“127.0.0.1:8888”);
socketio.on('id',函数(数据){
id=数据;
});
socketio.on(“广播”,功能(数据){
if(id==data.id){
返回
}
App.MsgsController.addMsg(data.message);
});
socketio.on(“自己”,函数(数据){
App.MsgsController.addMsg(data.message);
});
App=Ember.Application.create();
App.Msg=Ember.Object.extend({
值:null
});
App.MsgsController=Ember.ArrayController.create({
内容:[],
addMsg:函数(值){
var msg=App.msg.create({
价值:价值
});
这个.pushObject(msg);
}
});
App.TextField=Ember.TextField.extend({
insertNewline:function(){
this.get(“controller”).send(“sendMsg”);
}
});
App.ApplicationController=Ember.Controller.extend({
currentMsg:'t',
sendMsg:函数(){
var currentMsg=this.get('currentMsg');
如果(当前消息){
emit(“message”,{message:currentMsg,id:id});
此.set('currentMsg','');
}
}
});
我想在App.ApplicationController.sendMsg调用后关注App.TextField

我试过了

App.TextField.$().focus()
但我似乎只能在它的方法中使用$()

有人能帮我吗

编辑: 好的,我找到了答案

App.TextField类似于“class”,视图上的是一个实例

我必须在视图中添加一个id

{{#view App.TextField valueBinding="currentMsg" placeholder="your message" id="mytextfield"}}{{/view}}
并使用jquery选择器访问该实例

$('#mytextfield').focus();

对视图使用didInsertElement钩子来处理jquery方法