-1
我将应用程序切换到RequireJS。RequireJS并在模块中使用this.id?
在我的应用程序中,我检测到用户点击某个具有特定类的元素时。
我使用click事件和this.id来获取元素的唯一ID。
现在我已经将这个函数移动到了Require模块,我只为this.id返回'undefined'。
我猜这个模块没有一个参考,这个函数被调用时被点击了什么。
我也似乎无法通过this.id模块。
'使用关键字作为标识符是无效'。
那么,如何获得点击元素的唯一ID?
$(document).on('click', '.userSelect', function (myID) {
var retConvo = getConvoID.convoData();
convoID = retConvo.convo;
isGroup = retConvo.group;
console.log("Conversation ID is: " + convoID + " and IsGroup: " + isGroup);
});
这里是模块代码它调用。
define(function() {
return {
convoData: function(myID) {
var userSelected = this.id;
console.log('User Selected ID is: ' + userSelected);
if (userSelected == myID) {
alert("You can't message yourself.");
return false;
} else {
console.log("Selected User ID is: " + this.id);
// change background to show user is selected.
$("div.userSelected").removeClass("userSelected");
$(this).addClass("userSelected");
convoID = this.id;
isGroup = 'N';
console.log("emitting convo users id: " + convoID);
return {
convo: convoID,
group: isGroup
};
}
}
}
});
因此,当它到达上面的this.id时,它是未定义的。当它全部在一个js文件中时工作得很好。
感谢您的任何帮助和指针。
很好的回答!谢谢。我在看似简单的事情上绊倒自己。 –