-4

正如标题所说,我无法弄清楚。我已经使用 Jasmine 尝试确保它已定义并且它无法识别该文件。这是代码(顺便说一句,这是一个在线教程):

    Notes.controller = (function ($, dataContext) {
    var notesListSelector = "#notes-list-content";
    var noNotesCachedMsg = "<div>No notes cached</div>";
    var notesListPageId = "notes-list-page";
    var currentNote = null;

    function init() {
        dataContext.init();
        var d = $(document);
        d.bind("pagechange", onPageChange);
    }

    function onPageChange(event, data) {

        var toPageId = data.toPage.attr("id");

        switch (toPageId) {
            case notesListPageId:

                renderNotesList();
                break;
        }
    }

    function renderNotesList() {

        var notesList = dataContext.getNotesList();
        var view = $(notesListSelector);
        view.empty();

        if (notesList.length === 0) {

            $(noNotesCachedMsg).appendTo(view);
        } else {

            var notesCount = notesList.length;
            var note;
            var ul = $("<ul id=\"notes-list\" data-role = \"listview\"></ul>".appendTo(view);
            for (var i =0; i<notesCount; i++) {
                note = notesList[i];
                $("<li>" + "<a data-url =\"index.html#note-editor-page?noteId=" + note.id +
                "\" href=\"index.html#note-editor-page?noteId=" +note.id + "\">" + "<div>" +
                note.title + "</div>" + "<div class=\"list-item-narrative\">" + note.narrative
                + "</div>" + "</a>" + "</li>").appendTo(ul);
            }

            ul.listview();
        }


    };

    return {

        init: init
    }

})(jQuery,Notes.dataContext); 

我什至尝试用开发人员提供的源代码替换所有这些,但它仍然是未定义的,所以这可能是软件配置问题吗?

谢谢

4

1 回答 1

1

)在这一行中缺少 a :

var ul = $("<ul id=\"notes-list\" data-role = \"listview\"></ul>".appendTo(view);

应该是:

var ul = $("<ul id=\"notes-list\" data-role = \"listview\"></ul>").appendTo(view);

此外(虽然不太可能是您的错误的原因),这里不需要这个尾随分号:

function renderNotesList() {
    ...
};
于 2012-05-28T14:27:45.543 回答