[英]Need to be able to recognize the email variable to complete the actor line
請看一下我的代碼。 我正在嘗試使用頁面頂部附近設置的變量來設置actor。 名稱工作正常,但我無法收到電子郵件。 您能告訴我如何修改代碼,以便識別電子郵件變量嗎? 現在它說“ mailto:email”,我知道那是錯誤的,並且不起作用。 名稱確實有效,但是,我知道我很親近。 謝謝。
$("#myButton").click(function(){
var name = $("#nameID").val();
var email = $("#emailID").val();
// Save the name in localStorage.
localStorage.setItem('name', name);
// Save the email in localStorage.
localStorage.setItem('email', email);
init();
document.location.replace("page2.html");
});
function init() {
var stmt = new ADL.XAPIStatement(
new ADL.XAPIStatement.Agent('mailto:email', name),
new ADL.XAPIStatement.Verb('http://adlnet.gov/expapi/verbs/completed', 'completed'),
new ADL.XAPIStatement.Activity('act:http://johnmenken.blogspot.com/2016/01/practice-sending-xapi-statements.html', 'Diamond in the Rough',
'Article on curation by Ben Betts and Allison Anderson.')
);
//generates a unique ID for the statement
stmt.generateId();
//Other contextual information about the Activity
stmt.addOtherContextActivity( new ADL.XAPIStatement.Activity('Category:Curation') );
//Registration: An instance of a learner experiencing a particular Activity.
stmt.generateRegistration();
ADL.XAPIWrapper.changeConfig({
'endpoint': 'https://lrs.adlnet.gov/xapi/',
'user': 'xapi-tools',
'password': 'xapi-tools',
'auth': 'xapi-tools'
});
ADL.XAPIWrapper.sendStatement(stmt);
}
實際上,這不是Tin Can API問題,而是普通的JavaScript問題。
有多種方法可以解決此問題,但是根據您當前擁有的內容,我可以在點擊處理程序中構造Agent對象,並將其傳遞給init
函數,或者將“ name”和“ email”的值傳遞給init自己發揮作用。 Name是一個紅色鯡魚,它不太可能像您想象的那樣工作,您只是碰巧意外地將window.name
為global,而且很可能是空字符串。
init(email, name);
然后在init
里面:
function init(actorEmail, actorName) {
var stmt = new ADL.XAPIStatement(
new ADL.XAPIStatement.Agent('mailto:' + actorEmail, actorName),
我切換為在變量名中包含“演員”,以進行區分,但是沒有技術理由必須這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.