【发布时间】:2017-09-30 16:42:26
【问题描述】:
我创建了一个对象,其中包含许多嵌套可排序的操作,用于排序或修改我的类别。目前对象是这样的。
var CategoriesIndexView = {
options: {
baseIndent: 10,
defaultIndent: 38,
etc...
},
data: {},
events: {
"click button.collapsible-trigger": "toggleNestedRow",
"change #bulk-action-menu": "performBulkAction",
"click a.category-visible": "toggleCategoryVisibility",
"click #IndexDeleteButton": "bulkDelete"
},
initialize: function() {
this.bindNestedSortable()
},
bindNestedSortable: function() {
var a = this,
b = null;
$(".SortableList").nestedSortable(options);
},
toggleNestedRow: function(a){
var b = $(a.currentTarget),
c = $("i.la", b),
d = !c.hasClass("la-plus");
d ? this.expandCategory(b) : this.collapseCategory(b)
},
expandCategory: function(a) {},
...etc
我想添加EventListeners,基于“事件”数组,我在BackView.exteds 方法上看到了,但我使用的是简单的javascript。我可以在 CategoriesIndexView 中添加基于“事件”的 EventListener 吗?侦听器位于对象内部很重要,因为所有其他函数都使用对象的“this”。
【问题讨论】:
-
在MDN上查看
Function.prototype.bind。 -
CategoriesIndexView的events属性的对象内的属性值是否引用函数名称? -
CategoriesIndexView 中的函数
-
CategoriesIndexView 中的属性引用方法
-
在我使用的初始化时,jquery bind.. $("button.collapsible-trigger").bind("click", this.toggleNestedRow);它调用属性toggleNestedRow,但在属性内部我调用另一个属性但触发错误“this.expandCategory is not a function”
标签: javascript jquery object