我正在尝试通过aurelia-cli(au程序)启动的Aurelia JS项目中使用Kendo UI Splitter小部件。

为了提供可复制的示例,我在下面添加了一个bash脚本,该脚本使用au来启动新项目(由于au new仅是交互式的,并且没有在批处理模式下有用的选项,我必须在脚本中使用expect使其自动化),然后添加相关的源文件,最后构建并导出它。这是我的问题:


无论我做什么,水平拆分的高度都设置为300px;我想将其高度设置为父级的百分比-我该怎么做?
当我“导出”“生产”“捆绑”网站时,它无法加载-失败;它只能通过au run上的http://localhost:9000起作用。如何“导出”适当的“捆绑”网站?


关于大小/高度问题-这是通过index.html / au run查看localhost:9000时得到的结果:

css - 用于aurelia-cli元素的Kendo UI拆分器:以%为单位的高度,并且 bundle 导出?-LMLPHP

请注意,我在CSS类上为左窗格div元素使用的height设置被Kendo框架覆盖,该框架明确将高度写入该元素的内联style属性中。与此相关的是,我找到了http://docs.telerik.com/kendo-ui/controls/layout/splitter/how-to/expand-splitter-to-100-heightKendo UI Splitter height,这表明可能需要JavaScript才能执行此操作-但我不确定如何在Aurelia JS上下文中应用它。

关于捆绑问题:我已经找到了此文档(顺便说一句,是否可以在aurelia集线器URL中引用特定的框架版本?):

http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/the-aurelia-cli/4


  即使在开发过程中,Aurelia CLI应用程序也始终以捆绑模式运行。要构建您的应用程序,只需运行au build。 ...
  默认情况下,Aurelia CLI创建两个捆绑软件,一个app-bundle.js和一个vendor-bundle.js


我了解的方式是,node_modules中每个需要的依赖项都被“编译”在应用程序scripts/子文件夹中的两个.js文件中。因此,为了“导出”一个“生产”站点(假设au cli没有执行此操作的命令),可以只复制项目文件夹而没有其node_modules子文件夹,然后只需从中查看index.html副本在浏览器中-一切都应该正常工作。实际上,这确实对我有用,直到我尝试使用Kendo UI组件。

下面的脚本基本上在/tmp/testsplit中创建项目,使用au build进行构建,将没有node_modules/的项目文件夹复制到/tmp/testsplit-export,然后在原始项目文件夹中运行au run --watch。当我查看http://localhost:9000/file:///tmp/testsplit/index.html时,一切都很好-但是当我查看file:///tmp/testsplit-export/index.html时,什么也没有呈现,并且Firefox控制台日志告诉我:

...
DEBUG [templating] importing resources for mainpage.html <unavailable>  vendor-bundle.js:13938
ERROR [app-router] <unavailable>  vendor-bundle.js:13968
ERROR [app-router] Router navigation failed, and no previous location or fallbackRoute could be restored.  vendor-bundle.js:13968


我的版本是:

$ node --version
v4.2.6
$ npm --version
2.14.12
$ npm show aurelia-framework version
1.0.8
$ npm show aurelia-cli version
0.23.0


这是bash脚本:

#!/usr/bin/env bash
# uses `expect` and `rsync`: sudo apt-get install expect rsync
set -x
cd /tmp

REINSTALL=true # comment this var assignment to not recreate the project

if [ "$REINSTALL" == "true" ] ; then
  rm -rf /tmp/testsplit
  # npm install aurelia-cli -g # so we have `au` command
  # `au new` also creates new dir
  # note `au new --here` asks different questions!
  # wout --here: 1. Default ESNext (Default)
  # with --here: 1. Yes (Default) Would you like to create this project?
  #~ echo -r "1\r1\r" | au new testsplit # NOWORK, must use `expect`

  expect -c '
    set timeout -1
    proc abort {} {
      puts "Timeout or EOF\n"
      exit 1
    }
    spawn au new testsplit
    expect {
      "\\\[Default ESNext\\\]>"        { send "1\r" ; }
      default          abort
    }
    expect {
      "\\\[Yes\\\]>"          { send "1\r";  }
      default          abort
    }
    # note: the next q is the "Would you like to install the project dependencies?"
    # it downloads into node_modules (182MB), and may take a while
    expect {
      "\\\[Yes\\\]>"          { send "1\r";  }
      default          abort
    }
    expect eof
    catch wait result
    puts "Finished OK\n"
  '
fi

cd /tmp/testsplit

if [ "$REINSTALL" == "true" ] ; then
  npm install jquery kendo-ui-core aurelia-kendoui-bridge --save
fi

{ set +x ; } 2>/dev/null
function setfilename { FILENAME="$1"; echo $FILENAME; }

if [ "$REINSTALL" == "true" ] ; then
echo "    Patching files:"
export LOOKFOR="" REPLACER=""

setfilename "aurelia_project/aurelia.json" ;
IFS='' read -r -d '' REPLACER <<'EOF'
          "jquery",
          {
            "name": "kendo-ui-core",
            "path": "../node_modules/kendo-ui-core/js/",
            "main": "kendo.ui.core"
          },
          {
            "name": "aurelia-kendoui-bridge",
            "path": "../node_modules/aurelia-kendoui-bridge/dist/amd",
            "main": "index"
          },
EOF
IFS='' read -r -d '' LOOKFOR <<'EOF'
          "aurelia-templating-binding",
EOF
perl -pi -e 's/($ENV{"LOOKFOR"})/$1$ENV{"REPLACER"}/' "$FILENAME"

setfilename "src/main.js" ;
IFS='' read -r -d '' LOOKFOR <<'EOF'
    .feature('resources');
EOF
IFS='' read -r -d '' REPLACER <<'EOF'
    .feature('resources')
    // .plugin('aurelia-kendoui-bridge', kendo => kendo.core());
    .plugin('aurelia-kendoui-bridge');
EOF
perl -pi -e 's/(\Q$ENV{"LOOKFOR"}\E)/$ENV{"REPLACER"}/' "$FILENAME"
fi

echo "    Adding files:"

setfilename "src/app.html" ; cat > "$FILENAME" << 'EOF'
<template>
  <div>Test App</div>

  <div id="container">
    <router-view></router-view>
  </div>
</template>
EOF

setfilename "src/app.js" ; cat > "$FILENAME" << 'EOF'
export class App {
  configureRouter(config, router){
    config.title = 'Test App Title';
    config.map([
      { route: ['','mainpage'], name: 'mainpage', moduleId: './mainpage', nav: true, title:'Main Page' },
    ]);

    this.router = router;
  }
}
EOF

setfilename "src/mainpage.html" ; cat > "$FILENAME" << 'EOF'
<template>
  <require from="./mainpage.css"></require>
  <require from="aurelia-kendoui-bridge/splitter/splitter"></require>
  <!-- these two css must be present, else the drag handles are styled/positioned wrong! -->
  <require from="../node_modules/kendo-ui-core/css/web/kendo.common.core.min.css"></require>
  <require from="../node_modules/kendo-ui-core/css/web/kendo.default.min.css"></require>

  <div>( see also: http://aurelia-ui-toolkits.github.io/demo-kendo/#/samples/splitter-basic-use )</div>
  <div class="splitpane-holder" ak-splitter="k-orientation: horizontal;">
    <div class="pane-left"></div>
    <div class="pane-right"></div>
  </div>
</template>
EOF

setfilename "src/mainpage.js" ; cat > "$FILENAME" << 'EOF'
import * as $ from 'jquery';

//// both of these names seem to work the same:
// import {Splitter} from 'kendo-ui-core';
import {kendoSplitter} from 'kendo-ui-core';

export class Mainpage {

}
EOF

setfilename "src/mainpage.css" ; cat > "$FILENAME" << 'EOF'
html, body {
  height:100%;
  margin:0;
  padding:0;
  overflow:hidden;
}
.splitpane-holder {
  height: calc(100% - 6em);
  width: calc(100% - 2em);
  position: relative;
}
.pane-left, .pane-right { height: 100%; }
.pane-left { background-color: #AAA; }
.pane-right { background-color: #888; }
EOF

au build
rm -rf /tmp/testsplit-export
# add /. at end of source folder in rsync so hidden files are copied, else source will be copied as a folder inside destination
rsync -av /tmp/testsplit/. /tmp/testsplit-export --exclude node_modules
echo -e "Exported /tmp/testsplit-export/index.html\n"

au run --watch

最佳答案

此代码在所有浏览器中均可用,用“水平分隔符”代替“水平分隔符”?

<div id="horizontal"  role="horizontal" style="height: 100%;">


....

<style>
html,
body {height:100%; padding:0; margin:0;}
body {display:flex; flex-direction:column;}
#horizontal {flex-grow:1;}

关于css - 用于aurelia-cli元素的Kendo UI拆分器:以%为单位的高度,并且 bundle 导出?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41203950/

10-16 19:36