Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在主干js页面中加载额外条件_Javascript_Jquery_Backbone.js - Fatal编程技术网

Javascript 在主干js页面中加载额外条件

Javascript 在主干js页面中加载额外条件,javascript,jquery,backbone.js,Javascript,Jquery,Backbone.js,我有一个外部开发的主干应用程序-最初我在第一行执行定义和注入jquery等操作-第7个参数是“工具模板”) 我 另外,为了清晰/容易,这里删除了很多代码(因为所有其他代码都超过800行)&这对我来说都是新的,所以请随意指出任何明显的错误 第8行-我有以下行: window.isMobileDevice ? "text!views/tools/templates/i_tools.html" : "text!views/tools/templates/tools.html", 这基本上是“如果移动

我有一个外部开发的主干应用程序-最初我在第一行执行定义和注入jquery等操作-第7个参数是“工具模板”) 我

另外,为了清晰/容易,这里删除了很多代码(因为所有其他代码都超过800行)&这对我来说都是新的,所以请随意指出任何明显的错误

第8行-我有以下行:

window.isMobileDevice ? "text!views/tools/templates/i_tools.html" : "text!views/tools/templates/tools.html",
这基本上是“如果移动设备加载移动页面,则加载标准(桌面)页面”

我想用一些额外的逻辑来修正这一点,但不确定如何

我想加上另一个条件,基本上是这样的:

if (mobile device) 
  Load mobile page (as is now) e.g mobile-tools.html
else
  if (stampVar == true)
    load desktop stamp page e.g stamp-tools.html
  else
    load the standard desktop page e.g tools.html
有什么办法吗?stampVar基本上是真/假的,我正在尝试解决如何从现有js对象动态加载它

 define([
  "jquery",
  "backbone",
  "config",
  "models/model",
  "collections/collection",
  "views/tools/toolsBase",
   window.isMobileDevice ? "text!views/tools/templates/i_tools.html" : "text!views/tools/templates/stamper_tools.html",
window.isMobileDevice ? "text!views/tools/templates/i_editor.html" : "text!views/tools/templates/editor.html",
window.isMobileDevice ? "text!views/tools/templates/i_txts.html" : "text!views/tools/templates/txts.html",
window.isMobileDevice ? "text!views/tools/templates/i_txtsItem.html" : "text!views/tools/templates/txtsItem.html",
"text!views/tools/templates/fontItem.html",
"curvetext"
],
function ($, Backbone, Config, Model, Collection, ToolsBase, ToolsTmpl, EditorTmpl, TxtTmpl, TxtItemTmpl, FontItemTmpl) {
"use strict";
var View = ToolsBase.extend({

    initialize: function() {
        var self = this;
        if (window.isMobileDevice) {
            $(window).bind("resize.app", _.bind(this.resizeTools, this));
        }
    },

    render: function() {
        var self = this, tpl_data, tools_tpl_data;
        $('.customtool-title .tools-tabs').show();
        self.stickerSetup();

        //console.log(app.ctors);
        tools_tpl_data = {
            tips: app.settings.tips,
            isCompetition: app.settings.competition !== undefined,
            allowCodes: app.ctors["toolsCtor"].getAllowCodes(),
            customType: 'stamper'
        };

        if (app.settings.competition !== undefined) {
            tools_tpl_data.competition = app.settings.competition
        }

        console.log(ToolsTmpl);

        self.$el.find(".tools").append(_.template(ToolsTmpl, tools_tpl_data));

        tpl_data = {
            stickerTxtTop : self.selectedTxt.top,
            stickerTxtMiddle : self.selectedTxt.middle,
            stickerTxtBottom : self.selectedTxt.bottom,
            selectedtitle : self.selectedTitle,
            selectedtemplate : self.selectedTemplate,
            stickerTemplate : Config.templates + self.selectedTemplate + Config.templateExtension,
            isCompetition : app.settings.competition !== undefined,
            designType: app.ctors["toolsCtor"].getDesignType(),
            tips: app.settings.tips,

            selectedCodes : self.selectedCodes,
            selectedPoints : self.selectedPoints
        };

        if (app.settings.competition !== undefined) {
            tpl_data.competition = app.settings.competition;
        }

        if (self.backgroundType === "color") {
            tpl_data.stickerBgImage = null;
            tpl_data.stickerFgImage = this.getFgPath(self.stickerFgImage);
            self.$el.find(".editor").append(_.template(EditorTmpl, tpl_data));
            $(".customtool-background").hide();
            $('.customtool-fill').css({
                background: self.stickerBgColor,
                opacity: self.stickerBgOpacity
            }).show();
        } else {
            tpl_data.stickerFgImage = this.getFgPath(self.stickerFgImage);
            tpl_data.stickerBgImage = this.getBgPath(self.stickerBgImage);
            self.$el.find(".editor").append(_.template(EditorTmpl, tpl_data));
            $(".customtool-background").show();
            $('.customtool-fill').hide();
        }

        self.applyTextFormatting();
        self.refreshArcs(1,".customtool-toptext", self.selectedTxt.top.arc);
        self.refreshArcs(2,".customtool-middletext", self.selectedTxt.middle.arc);
        self.refreshArcs(3,".customtool-bottomtext", self.selectedTxt.bottom.arc);

        self.toggleCodes();

        if (app.settings.competition !== undefined && !window.isMobileDevice) {
            $('#dialog-form').dialog({
                autoOpen: false,
                width: 600,
                modal: true,
                zIndex: 1001,
                dialogClass: 'competition-dialog',
                draggable: false,
                buttons: [{
                    'text': "Create Another",
                    'class': 'pull-right createanother',
                    'style': 'display:none',
                    'click': function(e) {
                        self.restart(e);
                        return false;
                    }
                }, {
                    'text': "Enter Competition",
                    'class': 'pull-right green enter',
                    'disabled': true,
                    'click': function(e) {
                        self.competitionEnter(e);
                        return false;
                    }
                }, {
                    'text': "Order",
                    'class': 'pull-right continue green',
                    'style': 'display:none',
                    'click': function(e) {
                        self.competitionContinue(e);
                        return false;
                    }
                }, {
                    'text': "Cancel",
                    'class': 'pull-left cancelcomp',
                    'click': function(e) {
                        self.competitionCancel(e);
                        return false;
                    }
                }]
            });
        }

        if (app.settings.competition !== undefined) {
            _gaq.push(['_trackPageview', '/sticker-competition/editor']);
        }

        if (!window.isMobileDevice) {
            app.trigger("tools:bg");
        }
    }

}, {
    sticker_id: null,
    toolsOpen: false
});
return View;
});

您应该能够使用函数或嵌套的三元运算符(busomething,如
isMobileDevice?'firstTemplate':someOtherCondition?'secondTemplate':'thirdTemplate';
,尽管它有点凌乱,因此通常不推荐使用)。关于如何做到这一点,您有什么想法吗(即使这不是最好的方法..任何方法都可以在mo中使用):)我发布的内容应该有效(
ismobiledevice?'mobiletools.html':stampVar?'stampVar':'tools.html'
),但也许可以尝试使用类似于
“视图/工具/工具库”:(函数(){……返回…})()
干杯可以尝试一下