我正在尝试在 Aurelia JS 元素中使用 Kendo UI Splitter 小部件,该元素是通过 aurelia-cli(au
程序)启动的。
为了有一个可重现的例子,我在下面添加了一个 bash
脚本,它使用 au
开始一个新元素(因为 au new
只是交互式的,并且没有在批处理模式下有用的选项,我不得不在脚本中使用 expect
来自动化它),然后添加相关的源文件,最后构建并导出它.这是我的问题:
- 无论我做什么,水平分割的高度都设置为 300px;我想将其高度设置为父级的百分比 - 我该怎么做?
- 当我“导出”一个“生产”“bundle ”网站时,它无法加载 - 它失败了;它只能通过
http://localhost:9000
上的au run
运行。我怎样才能“导出”一个合适的“bundle ”站点?
关于大小/高度问题 - 这是我通过 au run
/localhost:9000
查看 index.html
时得到的结果:
请注意,我在我的 CSS 类中为左 Pane div 元素使用的 height
设置被 Kendo 框架覆盖,该框架明确将高度写入内联 style
元素的属性。与此相关,我找到了http://docs.telerik.com/kendo-ui/controls/layout/splitter/how-to/expand-splitter-to-100-height和 Kendo UI Splitter height ,这表明可能需要 JavaScript 来执行此操作 - 但我不确定如何在 Aurelia JS 上下文中应用它。
关于 bundle 问题:我找到了这个文档(顺便说一句,是否可以在 aurelia hub URL 中引用特定的框架版本?):
http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/the-aurelia-cli/4
Aurelia CLI apps always run in bundled mode, even during development. To build your app, simply run
au build
. ...
By default, the Aurelia CLI creates two bundles, anapp-bundle.js
, and avendor-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
最佳答案
此代码适用于所有浏览器,用“splitpane-holder”代替“horizontal”?
<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 元素 : height in %, 和 bundle 导出的 Kendo UI 拆分器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41203950/