gpt4 book ai didi

javascript - WebStorm 速度模板引擎

转载 作者:行者123 更新时间:2023-11-30 17:21:11 26 4
gpt4 key购买 nike

我在使用 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 = "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},如 docs 中所示。

模板代码

应该是这样的:

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

输入

文件名:young_people
pluralName: child
singularName: children

结果:

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

var pluralUrlBase = apiurl + 'child';
var singularUrlBase = apiurl + 'children';

this.get = function (id) {
if (this.get > 1) {
return $http.get(singularUrlBase + "/" + id);
}
else {
return $http.get(pluralUrlBase + "/" + id);
}
}
}]);

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

关于javascript - WebStorm 速度模板引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com