Javascript 使用{index+;1}}angularjs更改参数
我尝试用Javascript 使用{index+;1}}angularjs更改参数,javascript,angularjs,highcharts,angularjs-ng-repeat,Javascript,Angularjs,Highcharts,Angularjs Ng Repeat,我尝试用ng repeat 这里是html: <tr data-ng-repeat="key in keys"> <td> <div style="width: 140px; height: 37px; margin: 0 auto" class="hc-pie" items="values{{index+1}}"></div> </td> <td>{{key.perfomance}}
ng repeat
这里是html:
<tr data-ng-repeat="key in keys">
<td>
<div style="width: 140px; height: 37px; margin: 0 auto" class="hc-pie" items="values{{index+1}}"></div>
</td>
<td>{{key.perfomance}}</td>
<td>{{key.current}}</td>
<td>{{key.previous}}</td>
<td>{{key.variance}}</td>
</tr>
$scope.values1=[
['value', 42.4],
['value', 33.2],
['value', 34.5],
['value', 39.7],
['value', 52.6],
['value', 75.5],
['value', 57.4],
['value', 60.4],
['value', 47.6],
['value', 39.1],
['value', 46.8],
['value', 51.1]
];
$scope.values2=[
['value', 32.4],
['value', 13.2],
['value', 84.5],
['value', 19.7],
['value', 22.6],
['value', 65.5],
['value', 77.4],
['value', 90.4],
['value', 17.6],
['value', 59.1],
['value', 76.8],
['value', 21.1]
];
$scope.keys=[
{perfomance:'ccc',
current:'a',
previous:'b',
variance:'c',
plus:false,
},{perfomance:'bbb',
current:'a',
previous:'b',
variance:'c',
plus:true,
},{perfomance:'aaa',
current:'a',
previous:'b',
variance:'c',
plus:false,
}
];
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
console.log(2);
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
var chart = new Highcharts.Chart({
chart: {
renderTo: element[0],
type: 'column',
backgroundColor: null
},
title: {
text: null
},
subtitle: {
text: null
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
labels: {
enabled: false
},
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
tickLength: 0
},
yAxis: {
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
min: 0,
title: {
text: null
},
labels: {
enabled: false
}
},
tooltip: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
states: {
hover: {
color: '#FFFFFF'
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Value',
color: '#EC5B00',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
和另一个数据:
<tr data-ng-repeat="key in keys">
<td>
<div style="width: 140px; height: 37px; margin: 0 auto" class="hc-pie" items="values{{index+1}}"></div>
</td>
<td>{{key.perfomance}}</td>
<td>{{key.current}}</td>
<td>{{key.previous}}</td>
<td>{{key.variance}}</td>
</tr>
$scope.values1=[
['value', 42.4],
['value', 33.2],
['value', 34.5],
['value', 39.7],
['value', 52.6],
['value', 75.5],
['value', 57.4],
['value', 60.4],
['value', 47.6],
['value', 39.1],
['value', 46.8],
['value', 51.1]
];
$scope.values2=[
['value', 32.4],
['value', 13.2],
['value', 84.5],
['value', 19.7],
['value', 22.6],
['value', 65.5],
['value', 77.4],
['value', 90.4],
['value', 17.6],
['value', 59.1],
['value', 76.8],
['value', 21.1]
];
$scope.keys=[
{perfomance:'ccc',
current:'a',
previous:'b',
variance:'c',
plus:false,
},{perfomance:'bbb',
current:'a',
previous:'b',
variance:'c',
plus:true,
},{perfomance:'aaa',
current:'a',
previous:'b',
variance:'c',
plus:false,
}
];
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
console.log(2);
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
var chart = new Highcharts.Chart({
chart: {
renderTo: element[0],
type: 'column',
backgroundColor: null
},
title: {
text: null
},
subtitle: {
text: null
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
labels: {
enabled: false
},
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
tickLength: 0
},
yAxis: {
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
min: 0,
title: {
text: null
},
labels: {
enabled: false
}
},
tooltip: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
states: {
hover: {
color: '#FFFFFF'
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Value',
color: '#EC5B00',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
还有我的指令:
<tr data-ng-repeat="key in keys">
<td>
<div style="width: 140px; height: 37px; margin: 0 auto" class="hc-pie" items="values{{index+1}}"></div>
</td>
<td>{{key.perfomance}}</td>
<td>{{key.current}}</td>
<td>{{key.previous}}</td>
<td>{{key.variance}}</td>
</tr>
$scope.values1=[
['value', 42.4],
['value', 33.2],
['value', 34.5],
['value', 39.7],
['value', 52.6],
['value', 75.5],
['value', 57.4],
['value', 60.4],
['value', 47.6],
['value', 39.1],
['value', 46.8],
['value', 51.1]
];
$scope.values2=[
['value', 32.4],
['value', 13.2],
['value', 84.5],
['value', 19.7],
['value', 22.6],
['value', 65.5],
['value', 77.4],
['value', 90.4],
['value', 17.6],
['value', 59.1],
['value', 76.8],
['value', 21.1]
];
$scope.keys=[
{perfomance:'ccc',
current:'a',
previous:'b',
variance:'c',
plus:false,
},{perfomance:'bbb',
current:'a',
previous:'b',
variance:'c',
plus:true,
},{perfomance:'aaa',
current:'a',
previous:'b',
variance:'c',
plus:false,
}
];
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
console.log(2);
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
var chart = new Highcharts.Chart({
chart: {
renderTo: element[0],
type: 'column',
backgroundColor: null
},
title: {
text: null
},
subtitle: {
text: null
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
labels: {
enabled: false
},
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
tickLength: 0
},
yAxis: {
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
min: 0,
title: {
text: null
},
labels: {
enabled: false
}
},
tooltip: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
states: {
hover: {
color: '#FFFFFF'
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Value',
color: '#EC5B00',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
指令('hcPie',函数(){
返回{
限制:“C”,
替换:正确,
范围:{
项目:'='
},
控制器:函数($scope、$element、$attrs){
控制台日志(2);
},
模板:“不工作”,
链接:函数(范围、元素、属性){
var图表=新的Highcharts.图表({
图表:{
renderTo:元素[0],
键入:“列”,
背景颜色:空
},
标题:{
文本:空
},
副标题:{
文本:空
},
xAxis:{
类别:[
“一月”,
二月,,
“三月”,
“四月”,
“五月”,
"六月",,
七月,,
"八月",,
"九月",,
“十月”,
十一月,,
“十二月”
],
标签:{
已启用:false
},
网格线宽:0,
minorGridLineWidth:0,
lineColor:'透明',
长度:0
},
亚克斯:{
网格线宽:0,
minorGridLineWidth:0,
lineColor:'透明',
分:0,,
标题:{
文本:空
},
标签:{
已启用:false
}
},
工具提示:{
已启用:false
},
打印选项:{
专栏:{
点填充:0,
边框宽度:0,
国家:{
悬停:{
颜色:“#FFFFFF”
}
}
}
},
图例:{
已启用:false
},
系列:[{
名称:“值”,
颜色:“#EC5B00”,
数据:scope.items
}]
});
范围.$watch(“项目”),功能(newValue){
chart.series[0].setData(newValue,true);
},对);
}
}
});
我试图用items=“values{{{index+1}}}”
更改值,但它在html中显示相同的值,而不是items=“values1”
显示另一个highchart
但它不会改变
我遗漏了什么?您不应该使用带双向绑定的大括号,因为它会使角度表达式无效 在您的例子中,您只需要使用括号表示法,以便通过动态键引用对象属性(还要注意,它是
$index
而不是index
):
您不应该在双向绑定中使用大括号,因为它会使角度表达式无效 在您的例子中,您只需要使用括号表示法,以便通过动态键引用对象属性(还要注意,它是
$index
而不是index
):
重组数据:
$scope.values[1]=[
{'value': 42.4},
{'value': 33.2}
]
$scope.values[2]=[
{'value': 32.4},
{'value': 13.2}
]
然后在HTML中使用:
<div class="hc-pie" items="values[index+1]"></div>
重组数据:
$scope.values[1]=[
{'value': 42.4},
{'value': 33.2}
]
$scope.values[2]=[
{'value': 32.4},
{'value': 13.2}
]
然后在HTML中使用:
<div class="hc-pie" items="values[index+1]"></div>
我不知道这有什么不对,但您应该使用“$index”而不是index@saikumar我用过,但它在html中没有变化,它显示为
这个问题描述真的缺乏详细信息您的控制台是否有任何错误?@Mikey it give syntax error,但是我不明白它在哪里,我不知道这有什么错,但是你应该用“$index”而不是index@saikumar我用过,但它在html中没有变化,它显示为
这个问题描述真的缺乏详细信息您的控制台是否有任何错误?@Mikey it give syntax error,但我不明白它在哪里,我认为这不会正确评估。您仍然需要花括号进行计算。谢谢,但输出显示:items=“'values'+(index+1)”
而不是items=“values1”
,因为我试图解释,当然,我误解了您的需要。在这种情况下,您只需要使用括号表示法,以便通过动态键引用对象属性。@dfsq I试图将items=“values”
与{$index}
更改为items=“values1”
,items=“values2”
,items=“valuesn”
@FrontEndist所以我发布的内容应该可以做到这一点。我认为这不会正确评估。您仍然需要花括号进行计算。谢谢,但输出显示:items=“'values'+(index+1)”
而不是items=“values1”
,因为我试图解释,当然,我误解了您的需要。在这种情况下,您只需要使用括号表示法,以便通过动态键引用对象属性。@dfsq我试图用{$index}
将items=“values”
更改为items=“values1”
,items=“values2”
,items=“valuesn”
@FrontEndist,所以我发布的内容应该可以做到这一点。