向我的Ember应用程序中添加自定义帮助程序功能或ember-truth-helpers

问题描述 投票:0回答:2

我有一个Ember应用程序,也许它从Visual Studio开始,是一些MVC或某些项目模板,后来又添加了,现在,我正努力通过多种方式添加“ ember-truth-helpers”,例如使用yarn add或npm add ,以不添加任何方式的方式,我要做的就是执行以下代码:

{{#if (eq "complete" "complete")}}  {{! works! }}
{{log 'Complete 1'}}
{{/if}}

我收到以下错误:ember.debug.js:43618未捕获(承诺)错误:编译错误:eq不是帮助器

而且我的package.json文件如下所示

{ 
   "name":"ims-ember",
   "version":"1.0.0",
   "main":"index.js",
   "scripts":{ 
      "build":"ember build",
      "babel-preset-env":"^1.7.0",
      "lint:hbs":"ember-template-lint .",
      "babel-preset-es2016":"^6.24.1",
      "lint:js":"eslint .",
      "bootbox.js":"^4.3.0",
      "start":"JOBS=1 ember serve",
      "bootstrap":"^3.3.7",
      "test":"ember test"
   },
   "author":"",
   "license":"ISC",
   "description":"",
   "dependencies":{ 
      "babel-core":"^6.26.3",
      "babel-polyfill":"^6.26.0",
      "babel-preset-env":"^1.7.0",
      "babel-preset-es2016":"^6.24.1",
      "bootbox.js":"^4.3.0",
      "bootstrap":"^3.3.7",
      "bootstrap-datepicker":"^1.9.0",
      "bootstrap-hover-dropdown":"^2.2.1",
      "chosen-js":"^1.8.7",
      "datatables":"^1.10.18",
      "ember-cli-windows":"github:felixrieseberg/ember-cli-windows",
      "file-loader":"^4.2.0",
      "font-awesome":"^4.7.0",
      "gulp":"^4.0.2",
      "gulp-babel":"^8.0.0",
      "gulp-clean":"^0.4.0",
      "gulp-clean-css":"^4.2.0",
      "gulp-concat":"^2.6.1",
      "gulp-concat-sourcemap":"^1.3.1",
      "gulp-declare":"^0.3.0",
      "gulp-filter":"^6.0.0",
      "gulp-if":"^3.0.0",
      "gulp-insert":"^0.5.0",
      "gulp-less":"^4.0.1",
      "gulp-replace":"^1.0.0",
      "gulp-uglify":"^3.0.2",
      "gulp-wrap":"^0.15.0",
      "gulp-wrap-file":"^0.1.2",
      "handlebars":"^4.4.2",
      "icons-loader":"0.0.6",
      "inputmask":"^4.0.9",
      "jquery":"^3.4.1",
      "jquery-ui":"^1.12.1",
      "json-stringify-safe":"^5.0.1",
      "lightbox2":"^2.11.1",
      "loader-utils":"^1.2.3",
      "moment":"^2.24.0",
      "mssql":"^5.1.0",
      "node-sass":"^4.12.0",
      "npm":"^6.13.0",
      "popper.js":"^1.15.0",
      "rimraf":"^3.0.0",
      "sass-loader":"^8.0.0",
      "schema-utils":"^2.4.1",
      "toastr":"^2.1.4",
      "typeahead.js":"^0.11.1",
      "uglifyjs-webpack-plugin":"^2.2.0",
      "uuid":"^3.3.3"
   },
   "devDependencies":{ 
      "@babel/core":"^7.6.2",
      "@babel/preset-env":"^7.6.2",
      "babel-loader":"^8.0.6",
      "css-loader":"^3.2.0",
      "ember-truth-helpers":"^2.1.0",
      "install":"^0.13.0",
      "less-loader":"^5.0.0",
      "style-loader":"^1.0.0",
      "webpack":"^4.41.0",
      "webpack-cli":"^3.3.10"
   }
}

请帮忙吗?

javascript ember.js ember-cli
2个回答
0
投票

我已通过助手功能解决了此问题-在这里,以前的开发人员将所有帮助程序功能放在一个文件中,这引起了他的困惑,他将具有这些帮助程序功能的其他文件放在了不同的目录中-看来我需要清理它。您对检查定义的建议帮助我研究了webpack.config.js(异步帮助程序,异步__parts),在那里他将所有文件脚本组合在一起并生成一个js文件,并将其写入app.js。他(或我不确定的Ember)遵循的惯例是骆驼套。例如,对于他如下编写的一个辅助功能以及相同的ifCond.js文件,将其转换为“替换”,我们可以将其用作车把中的替换]

IMS.ReplaceHelper = Ember.Helper.extend({
    compute(args) {
        return args[0].replace(new RegExp(args[1], 'ig'), args[2]);
    }
})

[如果假设,如果有两个单词-那么它紧跟着骆驼的外壳(您知道)。完全完成了,我根据需要编写了一些自己的帮助程序功能-非常感谢每个跳进来帮助我的人-非常感谢,而且我没有任何语言可以形容我的幸福-谢谢。我自己的助手功能如下:

    IMS.IsLastHelper = Ember.Helper.extend({
        compute(args) {
            var list = args[0];
            var item = args[1];

        if (Array.isArray(list)) {
            var id = list.indexOf(item);
            return id == list.length - 1;
        }
        return false;
    }
})
IMS.IsFirstHelper = Ember.Helper.extend({
    compute(args) {
        var list = args[0];
        var item = args[1];

        if (Array.isArray(list)) {
            var id = list.indexOf(item);
            return id == 0;
        }
        return false;
    }
})

我用如下语法调用它们:

                        {{#each  model.novs as |nov index|}}
                        {{#if (isFirst model.novs nov)}}
                        ({{nov.NOVNumber}}:
                        {{else}}
                        {{nov.NOVNumber}}:
                        {{/if}}
                        {{#each  nov.Violations as |novv index|}}
                        {{#unless (isLast nov.Violations novv)}}
                        {{novv.ViolationNumber}},
                        {{else}}
                        {{#if (isLast model.novs nov)}}
                        {{novv.ViolationNumber}}
                        {{else}}
                        {{novv.ViolationNumber}};
                        {{/if}}
                        {{/unless}}
                        {{/each}}
                        {{#if (isLast model.novs nov)}}
                        )
                        {{/if}}
                        {{/each}}

再次感谢该组中的每个人。 :pray:


0
投票

我已通过帮助程序功能解决了此问题-答案是以下链接:Adding custom helper functions or ember-truth-helpers to my Ember application

© www.soinside.com 2019 - 2024. All rights reserved.