如何调用索引中包含的函数.html在主干木偶集合中



非常新手的问题:

我关注David Sulc的书Backbone.Marionette.js:A Serious Progression,并尝试学习Backbone和木偶。我想使用WordPress Gravity Forms Web API作为RestAPI服务器,因为我不懂任何服务器端语言。为了进行身份验证,我需要包含此JavaScript文件以生成模型中的rootUrl和集合中的Url:(http://www.gravityhelp.com/documentation/page/Web_API(JavaScript部分。

所以我需要在索引中包含 2 个脚本文件.html(位于根文件夹中(,然后像这样:

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>

然后在集合中(位于 js/entities/contact.js(,我需要这样做:

ContactManager.module("Entities", function(Entities, ContactManager, Backbone, Marionette, $, _){
Entities.ContactCollection = Backbone.Collection.extend({
    calculateSig: function(stringToSign, privateKey){
        var hash = CryptoJS.HmacSHA1(stringToSign, privateKey);
        var base64 = hash.toString(CryptoJS.enc.Base64);
        return encodeURIComponent(base64);
    },
    url: function(){
        var d = new Date,
         expiration = 3600 // 1 hour,
         unixtime = parseInt(d.getTime() / 1000),
         future_unixtime = unixtime + expiration,
         publicKey = "1234",
         privateKey = "abcd",
         method = "GET",
         route = "forms/1/entries";
        stringToSign = publicKey + ":" + method + ":" + route + ":" + future_unixtime;
        sig = this.calculateSig(stringToSign, privateKey);
        console.log(sig);
        return sig;
    },
    model: Entities.Contact
});
});

我遇到的第一个愚蠢问题是,如何在 Backbone 集合中的计算 Sig 中调用"CryptoJS.HmacSHA1"函数和"CryptoJS.enc.Base64"......如果我使用我的命名空间ContactManager.CryptoJS.HmacSHA1,它仍然说无法读取未定义的属性"HmacSHA1"。

不知道如何实现重力形式授权脚本来生成主干的 url。请帮忙!

问题是我的网站在SSL/HTTPS下,我使用http获取CryptoJS文件。所以我的模型/集合永远不会得到全局变量。

最新更新