如何将 bootstrap-datepicker 实现为 Aurelia 自定义元素
How to implement bootstrap-datepicker as Aurelia custom element
首先阅读 bootstrap 日期选择器的 http://www.danyow.net/jquery-ui-datepicker-with-aurelia/ and with inspiration from https://gist.github.com/charlespockert/6a1fef3f546f6d37d1dc here follows my attempt to implement the https://github.com/eternicode/bootstrap-datepicker 版本:
http://plnkr.co/edit/TkbT6E?p=preview
虽然我已经检查 bootstrap-datepicker 是否正确安装了 jspm 并且 .js 已加载,但我得到了 self.datePicker.datepicker is not a function(…)
。日期选择器确实出现了(确认 js 已正确加载),我可以 select 一个日期,但未设置该值。
我做错了什么?
更新:
一个友好的灵魂,@SamDeBlock,在 gitter 中。im/Aurelia 将这个 http://plnkr.co/edit/hKit8pigwL1ijr2DmbGP?p=preview 与依赖项放在一起,所以它会 运行。然而,当我在自己的应用程序中 运行ning 时,我不断收到上述错误。我将进一步调查它的问题并在此处更新,如果我弄清楚了这个问题。
更新二:
我现在已经将问题归结为系统问题。js/jspm。这也是上面的 plunkr 起作用的原因,因为它只是直接引用文件而不是在 config.js.
中定义它们
如果我手动添加文件,就像上面 plunkr 中建议的那样 - 如果我在 moment.js 文件中更改以下内容:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()
}(this, function () { 'use strict';
...
至:
(function (global = typeof window !== "undefined" ? window : this, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()
}(this, function () { 'use strict';
...
global = typeof window !== "undefined" ? window : this
部分..
然后它似乎可以工作,Aurelia 导航骨架也可以。
但为什么这是必要的?在没有所有黑客攻击的情况下,我怎样才能让它发挥作用?我在 Aurelia Navigation Starter 项目上构建了我的应用程序
https://github.com/aurelia/skeleton-navigation
很可能是 jspm 在执行 jspm install -y npm:bootstrap-datepicker
时导致了此问题,因此请检查 config.js
寻找这个:
"npm:bootstrap-datepicker@1.5.0": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"jquery": "npm:jquery@2.1.4"
},
并将其更改为:
"npm:bootstrap-datepicker@1.5.0": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"jquery": "github:components/jquery@2.1.4"
},
重要的部分是:"jquery": "github:components/jquery@2.1.4"
那么一切都应该通过 System.config 解决,而不需要 moment.js 解决方法或任何其他方法。
首先阅读 bootstrap 日期选择器的 http://www.danyow.net/jquery-ui-datepicker-with-aurelia/ and with inspiration from https://gist.github.com/charlespockert/6a1fef3f546f6d37d1dc here follows my attempt to implement the https://github.com/eternicode/bootstrap-datepicker 版本:
http://plnkr.co/edit/TkbT6E?p=preview
虽然我已经检查 bootstrap-datepicker 是否正确安装了 jspm 并且 .js 已加载,但我得到了 self.datePicker.datepicker is not a function(…)
。日期选择器确实出现了(确认 js 已正确加载),我可以 select 一个日期,但未设置该值。
我做错了什么?
更新:
一个友好的灵魂,@SamDeBlock,在 gitter 中。im/Aurelia 将这个 http://plnkr.co/edit/hKit8pigwL1ijr2DmbGP?p=preview 与依赖项放在一起,所以它会 运行。然而,当我在自己的应用程序中 运行ning 时,我不断收到上述错误。我将进一步调查它的问题并在此处更新,如果我弄清楚了这个问题。
更新二:
我现在已经将问题归结为系统问题。js/jspm。这也是上面的 plunkr 起作用的原因,因为它只是直接引用文件而不是在 config.js.
中定义它们如果我手动添加文件,就像上面 plunkr 中建议的那样 - 如果我在 moment.js 文件中更改以下内容:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()
}(this, function () { 'use strict';
...
至:
(function (global = typeof window !== "undefined" ? window : this, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()
}(this, function () { 'use strict';
...
global = typeof window !== "undefined" ? window : this
部分..
然后它似乎可以工作,Aurelia 导航骨架也可以。
但为什么这是必要的?在没有所有黑客攻击的情况下,我怎样才能让它发挥作用?我在 Aurelia Navigation Starter 项目上构建了我的应用程序 https://github.com/aurelia/skeleton-navigation
很可能是 jspm 在执行 jspm install -y npm:bootstrap-datepicker
时导致了此问题,因此请检查 config.js
寻找这个:
"npm:bootstrap-datepicker@1.5.0": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"jquery": "npm:jquery@2.1.4"
},
并将其更改为:
"npm:bootstrap-datepicker@1.5.0": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"jquery": "github:components/jquery@2.1.4"
},
重要的部分是:"jquery": "github:components/jquery@2.1.4"
那么一切都应该通过 System.config 解决,而不需要 moment.js 解决方法或任何其他方法。