Emberjs: Get the current element

左心房为你撑大大i 提交于 2019-12-30 07:51:52

问题


I am looking for something that's similar to the this of jQuery. I'm going to list below the code I have:

<script type="text/x-handlebars" data-template-name="uiMainContainerTaskList">
    <div class="uiMainContainerTaskListContent">
    {{#view App.TasksView}}
    {{#each App.tasksController.tasks}}
    <div class="uiMainContainerWideItem" {{action "taskClick" target="TasksView" on="click"}}>
        <div class="uiMainContainerWideItemCheckbox">{{view Em.Checkbox checkedBinding="isDone"}}</div>
        <div class="uiMainContainerWideItemText uiMainContainerWideItemTaskName">{{taskName}}</div>
        <div class="uiMainContainerWideItemText uiMainContainerWideItemTaskDescription">{{taskDescription}}</div>
        <div class="uiMainContainerWideItemText uiMainContainerWideItemTaskPriority">{{priority}}</div>
        <div class="uiMainContainerWideItemText uiMainContainerWideItemTaskDueDate">{{dueDate}}</div>
    </div>
    {{/each}}
    {{/view}}
    </div>
</script>  

I bind the taskClick action to the div.uiMainContainerWideItem. In my View I have:

App.TasksView = Em.View.extend({
    templateName: 'uiMainContainerTaskList',
        taskClick: function(e) {
            console.log($(this)); 
        }
});  

In jQuery, $(this) would be the current element (no children). Is there a way to get the current element in Ember as well?


回答1:


I believe you are looking for this.$().




回答2:


You can call this.get('element') to get the actual element.

See: Ember View Documentation




回答3:


I know is an old question but since views are deprecated (and if you are not needing this for a component), you can pass the action to the dom onclick event and get the event js object in the last parameter of the action.

Please check https://stackoverflow.com/a/37066157/2726189

hope it helps



来源:https://stackoverflow.com/questions/11849983/emberjs-get-the-current-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!