0

请看一下我的代码。我正在尝试使用页面顶部附近设置的变量来设置演员。名称工作正常,但我无法让电子邮件工作。您能告诉我如何修改代码以使其识别电子邮件变量吗?现在它说'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);
}
4

1 回答 1

0

这与其说是一个 Tin Can API 问题,不如说是一个普通的 JavaScript 问题。

有很多方法可以解决这个问题,但根据您目前所拥有的,我会在点击处理程序中构造 Agent 对象并将其传递给init函数,或者将“name”和“email”的值传递给 init 函数他们自己。名称是一条红鲱鱼,它不太可能按照您认为的方式工作,您只是碰巧偶然获得window.name了一个全局变量,而且很可能是空字符串。

init(email, name);

然后在里面init

function init(actorEmail, actorName) {

        var stmt = new ADL.XAPIStatement(
            new ADL.XAPIStatement.Agent('mailto:' + actorEmail, actorName),

我切换到在变量名中包含“演员”以进行区分,但没有技术原因必须这样做。

于 2016-06-22T21:44:13.497 回答