在实施Facebook时,JQuery Mobile忽略了数据角色

时间:2013-11-08 10:57:33

标签: javascript jquery facebook facebook-graph-api jquery-mobile

我正在尝试将Facebook功能应用到我的应用程序中。第一个功能是能够登录使用Facebook。第二个允许用户将Facebook中的朋友导入应用程序。

但问题是,当我使用FB API时,JQuery Mobile功能会停止。

如果删除Facebook API代码,布局将非常完美。这意味着如果我将带有data-role集的字段集添加到controlgroup,则不会将任何JQuery样式和函数应用于该元素及其子元素。

有没有人知道这个问题的解决方案? (应该有更多的JQuery Mobile应用程序使用社交API)。

Controller.js

this.handleContactsFacebook = function () {
        this.initialize();

        function retrieveContacts () {
            FB.api('/me/friends/?fields=id,first_name,middle_name,last_name,username,name', function(response) {
                (new Contact()).showContactListFacebook(response.data);
            });
        }

        FB.getLoginStatus(function (data) {
            if (data.status === 'connected') {
                retrieveContacts();
            }
            else if (data.status === 'not_authorized') {
                $.mobile.changePage("menu.html");
            }
            else {
                $.mobile.changePage("menu.html");
            }
        });
    };

contact.js

this.showContactListFacebook = function (contacts) {
        var fieldset = $("<div data-role=\"fieldcontain\">" +
        "<fieldset data-role=\"controlgroup\">" +
            "<legend>Agree to the terms:</legend>" +
            "<input type=\"checkbox\" name=\"checkbox-1\" id=\"checkbox-1\" class=\"custom\" />" +
            "<label for=\"checkbox-1\">I agree</label>" +
            "</fieldset>" +
        "</div>");
        $("fieldset").remove();
        $("#contactsFacebook").prepend(fieldset);
    };

http://forum.jquery.com/topic/jquery-mobile-ignored-data-role-when-implementing-facebook

1 个答案:

答案 0 :(得分:0)

尝试在代码中添加jQuery.noConflict()。 我认为facebook api可能会使用$ token和jquery(因此也是jquery mobile)

此处有更多信息:http://api.jquery.com/jQuery.noConflict/

你也可以尝试用jQuery替换$ for jquery代码,看看是否能解决冲突,即用$("fieldset").remove();替换jQuery.("fieldset").remove();