Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript WebStorm速度模板引擎_Javascript_Velocity_Webstorm - Fatal编程技术网

Javascript WebStorm速度模板引擎

Javascript WebStorm速度模板引擎,javascript,velocity,webstorm,Javascript,Velocity,Webstorm,我在使用velocity模板引擎的WebStorm中创建JavaScript模板时遇到问题 我试图获取的最终文档如下所示: app.service('Name', ['$http', function($http) { var singularUrlbase = apiurl + 'SingularName'; var pluralUrlbase = apiurl + 'PluralName'; this.get = function(id){ return $http.get(

我在使用velocity模板引擎的WebStorm中创建JavaScript模板时遇到问题

我试图获取的最终文档如下所示:

app.service('Name', ['$http', function($http) {
 var singularUrlbase = apiurl + 'SingularName';
 var pluralUrlbase = apiurl + 'PluralName';

 this.get = function(id){
   return $http.get( singularUrlBase + id );
 } 
}
#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = 'pluralUrlBase + "/" + id')

app.service('${NAME}', ['${DS}http', function(${DS}http) {

    var pluralUrlBase = apiurl + '$pluralName';
    var singularUrlBase = apiurl + '$singularName';

    this.get = function(id) {
        if (this.get > 1) {
            return ${DS}http.get( $url1 );
        }
        else {
            return ${DS}http.get( $url2 );
        }
    }
}]);
我正在尝试使用此模板:

#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = "singularUrlBase + '/' + s.Id")

app.service('${NAME}', ['$http', function($http) {

    var pluralUrlBase = apiurl + '$pluralName';
    var singularUrlBase = apiurl + '$singularName';

    this.get = function(id) {                        
        return $http.get( $url1 );
    };
}
问题是:

  • 它显示
    return$http.get($url1)
    而不是
    return$http.get(singularUrlBase+id)
  • 我不知道如何忽略
    $http
    ,WebStorm要求我设置$http变量,但我不想

要在jetbrains应用程序模板中转义
$
符号,您需要编写
${DS}
,如

模板代码 应该是这样的:

app.service('Name', ['$http', function($http) {
 var singularUrlbase = apiurl + 'SingularName';
 var pluralUrlbase = apiurl + 'PluralName';

 this.get = function(id){
   return $http.get( singularUrlBase + id );
 } 
}
#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = 'pluralUrlBase + "/" + id')

app.service('${NAME}', ['${DS}http', function(${DS}http) {

    var pluralUrlBase = apiurl + '$pluralName';
    var singularUrlBase = apiurl + '$singularName';

    this.get = function(id) {
        if (this.get > 1) {
            return ${DS}http.get( $url1 );
        }
        else {
            return ${DS}http.get( $url2 );
        }
    }
}]);
投入 文件名:
年轻人

pluralName:
子项

名称:
子项

结果:
注意:您的语法有点错误,我修复了最后两行;)

谢谢。“+”的问题是它使模板引擎崩溃。这就是为什么我使用#设置($url1='URLBASE+“/”+id')。但这个技巧不起作用。我明白了,我只是更新了我的代码,发现我为模板粘贴了错误的代码(需要一些咖啡)。在你的问题中没有使用
$url2
,我认为
$url1='singularUrlBase+“/“+id')
是可以的,但是你应该手动将
s
添加到复数名中,因为复数名的英文例外;)。我在这里对
“+”
没有任何问题,没有太多地使用模板文件,回答有点太快,但它似乎在这里工作。