简体   繁体   English

将自定义帮助函数或 ember-truth-helper 添加到我的 Ember 应用程序

[英]Adding custom helper functions or ember-truth-helpers to my Ember application

I have an Ember Application, maybe it started as Visual Studio some MVC or some project template and later they have added, now I am trying hard to add "ember-truth-helpers" in many ways like using yarn add or npm add, in any of the ways its not being added, all I am trying to do is to execute the below code:我有一个 Ember 应用程序,可能它从 Visual Studio 开始,一些 MVC 或一些项目模板,后来他们添加了,现在我正在努力以多种方式添加“ember-truth-helpers”,例如使用 yarn add 或 npm add,在它没有被添加的任何方式,我要做的就是执行以下代码:

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

I am getting the following error: ember.debug.js:43618 Uncaught (in promise) Error: Compile Error: eq is not a helper我收到以下错误:ember.debug.js:43618 Uncaught (in promise) Error: Compile Error: eq is not a helper

And my package.json file looks as below我的 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"
   }
}

any help please?请问有什么帮助吗?

I have fixed this issue with helper functions - Here it is, the previous developer put all the helper functions in one file, the confusion he created was, he put other files with those helper functions in different directories - it seems I need to clean that up.我已经用辅助函数解决了这个问题 - 就是这样,以前的开发人员将所有辅助函数放在一个文件中,他造成的混乱是,他将具有这些辅助函数的其他文件放在不同的目录中 - 看来我需要清理那个向上。 And your suggestion to check the define helped me to look into the webpack.config.js (async helpers, async __parts), there he is combining all the files scripts and generating as one js file which is written on to app.js.您检查定义的建议帮助我查看了 webpack.config.js(异步助手,异步 __parts),在那里他将所有文件脚本组合在一起并生成为一个写入 app.js 的 js 文件。 The convention he (or Ember I am not sure) followed was camel casing.他(或我不确定的 Ember)遵循的惯例是骆驼肠衣。 For example for one helper-function he written as below withing the same ifCond.js file, is converted as "replace", we can use it as replace in handlebar例如,对于他使用相同的 ifCond.js 文件编写如下的一个辅助函数,将其转换为“替换”,我们可以将其用作车把中的替换

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

If suppose, if there are two Words - then it follows the camel casing (you know it).如果假设,如果有两个词 - 那么它遵循骆驼外壳(你知道的)。 Totally completed and I have written some helper functions of my own as needed - thanks a lot for everybody who jumped-in to help me - thanks a lot and I don't have words how to describe how happy I am - thank you.完全完成,我已经根据需要编写了自己的一些辅助函数 - 非常感谢所有参与帮助我的人 - 非常感谢,我无法用言语来形容我有多高兴 - 谢谢。 My own helper functions as below:我自己的助手功能如下:

    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;
    }
})

And I called them with syntax as below:我用如下语法调用它们:

                        {{#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}}

Thanks again to everybody in this group.再次感谢这个小组的每一个人。 :pray: :祈祷:

I have fixed this issue with helper functions - answer is the below link: Adding custom helper functions or ember-truth-helpers to my Ember application我已经用辅助函数解决了这个问题 - 答案是下面的链接: 向我的 Ember 应用程序添加自定义辅助函数或 ember-truth-helpers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM