From fff7fae323dda8587b42ef35ac82a99e845a9d56 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sat, 8 Aug 2015 09:43:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E6=9D=BF=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=8A=A0=E8=BD=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 需要在 avalon.ready()之后再进行其他动作,需要先初始化模板路径。 --- static/src/js/app/admin/admin.js | 67 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/static/src/js/app/admin/admin.js b/static/src/js/app/admin/admin.js index 4145a45d..9c17e410 100644 --- a/static/src/js/app/admin/admin.js +++ b/static/src/js/app/admin/admin.js @@ -1,42 +1,47 @@ -define("admin", ["jquery", "avalon"], function($, avalon){ - function li_active(selector){ - $(selector).attr("class", "list-group-item active"); - } +define("admin", ["jquery", "avalon"], function ($, avalon) { - function li_inactive(selector){ - $(".list-group-item").attr("class", "list-group-item"); - } + avalon.ready(function () { - function show_template(url){ - $("#loading-gif").show(); - vm.template_url = url; - } - - var vm = avalon.define({ - $id: "admin", - template_url: "template/index/index.html", - hide_loading: function(){ - $("#loading-gif").hide(); + function li_active(selector) { + $(selector).attr("class", "list-group-item active"); } - }); - var hash = window.location.hash.substring(1); + function li_inactive(selector) { + $(".list-group-item").attr("class", "list-group-item"); + } - if(hash){ - li_active("#li-" + hash.replace("/", "-")); - show_template("template/" + hash + ".html"); - }else { - li_active("#li-index-index"); - } + function show_template(url) { + $("#loading-gif").show(); + vm.template_url = url; + } - window.onhashchange = function() { var hash = window.location.hash.substring(1); - if(hash){ - li_inactive(".list-group-item"); - li_active("#li-" + hash.replace("/", "-")); - show_template("template/" + hash + ".html"); + + if (!hash) { + hash = "index/index"; } - }; + + var vm = avalon.define({ + $id: "admin", + template_url: "template/" + hash + ".html", + hide_loading: function () { + $("#loading-gif").hide(); + } + }); + + avalon.scan(); + + li_active("#li-" + hash.replace("/", "-")); + + window.onhashchange = function () { + var hash = window.location.hash.substring(1); + if (hash) { + li_inactive(".list-group-item"); + li_active("#li-" + hash.replace("/", "-")); + show_template("template/" + hash + ".html"); + } + }; + }); }); \ No newline at end of file