仅显示一个 属性 object- 在许多属性对象中,其中 objects 被包裹在数组中
Display -only One property object- among many properties objec where objects are wrapped in array
请帮助,我刚开始阅读 angularJS
我有一个带有键的项目
scope.eventList=[];
for(){
var event = {
id : hash,
title : title,
url : 'http://www.xxxxx.com/',
start : start,
end : end,
allDay : false,
location : '',
description : '',
editable : true
};
$scope.eventList.push(event);
}
它给出了一个事件列表(objects 的数组):
[
{
id : hash,
title : "TITLE1" ,
url : 'https://www.xxxxx.com/',
start : start,
end : end,
allDay : false,
location : '',
description : '',
editable : true
},
{
id : hash,
title : "TITLE2" ,
url : 'https://www.xxxxx.com/',
start : start,
end : end,
allDay : false,
location : '',
description : '',
editable : true
}
]
我需要将其放入 ng-repeat 但只显示项目的标题
like : Title1
Title2
Title3
......
TitleN
尝试了以下但不起作用。
<div customEventName="{{item.title}}"
ng-model="item" ng-repeat="item.title in eventList track by $index">
{{item.title}}
</div>
非常感谢您的帮助。
data = [
{
id : 'hash',
title : "TITLE1" ,
url : 'https://www.xxxxx.com/',
start: 'start',
end : 'end',
},
{
id : 'hash',
title : "TITLE2" ,
url : 'https://www.xxxxx.com/',
start: 'start',
end : 'end',
}, {
id : 'hash',
title : "TITLE3" ,
url : 'https://www.xxxxx.com/',
start: 'start',
end : 'end',
},
]
var titles = data.map(({title})=> title)
console.log(titles)
在您的情况下,您不需要 ng-model
也 track by $index
。
您的问题是 ng-repeat
中 Y in X
的 Y
是 "target" 变量,它将包含数组 [=16= 中包含的当前项目].
那么正确的代码是:
<div
ng-repeat="item in eventList"
customEventName="{{item.title}}">
{{item.title}}
</div>
请帮助,我刚开始阅读 angularJS
我有一个带有键的项目
scope.eventList=[];
for(){
var event = {
id : hash,
title : title,
url : 'http://www.xxxxx.com/',
start : start,
end : end,
allDay : false,
location : '',
description : '',
editable : true
};
$scope.eventList.push(event);
}
它给出了一个事件列表(objects 的数组):
[
{
id : hash,
title : "TITLE1" ,
url : 'https://www.xxxxx.com/',
start : start,
end : end,
allDay : false,
location : '',
description : '',
editable : true
},
{
id : hash,
title : "TITLE2" ,
url : 'https://www.xxxxx.com/',
start : start,
end : end,
allDay : false,
location : '',
description : '',
editable : true
}
]
我需要将其放入 ng-repeat 但只显示项目的标题
like : Title1
Title2
Title3
......
TitleN
尝试了以下但不起作用。
<div customEventName="{{item.title}}"
ng-model="item" ng-repeat="item.title in eventList track by $index">
{{item.title}}
</div>
非常感谢您的帮助。
data = [
{
id : 'hash',
title : "TITLE1" ,
url : 'https://www.xxxxx.com/',
start: 'start',
end : 'end',
},
{
id : 'hash',
title : "TITLE2" ,
url : 'https://www.xxxxx.com/',
start: 'start',
end : 'end',
}, {
id : 'hash',
title : "TITLE3" ,
url : 'https://www.xxxxx.com/',
start: 'start',
end : 'end',
},
]
var titles = data.map(({title})=> title)
console.log(titles)
在您的情况下,您不需要 ng-model
也 track by $index
。
您的问题是 ng-repeat
中 Y in X
的 Y
是 "target" 变量,它将包含数组 [=16= 中包含的当前项目].
那么正确的代码是:
<div
ng-repeat="item in eventList"
customEventName="{{item.title}}">
{{item.title}}
</div>