在$ scope中,我有一个名为 thisProject 的对象,它在控制台中记录如下:
[ 0: {
[functions]: ,
__metadata: { },
AttachmentFiles: { },
Attachments: false,
AuthorId: 9,
CloseDate: null,
ContentType: { },
ContentTypeId: "0x010087886FAC81322548A66F903FF786897C",
Created: "2014-05-06T21:24:35Z",
Division: "Information Technology",
Division_ID: "21",
Due_Date: "2014-05-12T07:00:00Z",
EditorId: 9,
FieldValuesAsHtml: { },
FieldValuesAsText: { },
FieldValuesForEdit: { },
File: { },
FileSystemObjectType: 0,
FirstUniqueAncestorSecurableObject: { },
Folder: { },
GUID: "291f7307-b134-47e6-b13e-09fd86fe31ce",
ID: 6,
Id: 6,
Imported_From_Project: false,
Modified: "2014-05-06T21:24:35Z",
OData__UIVersionString: "1.0",
ParentList: { },
Project_Lead: "Eyre, Jane",
Priority: "High: Time Sensitive",
Priority_Group: "High",
Priority_ID: "3",
Project_GUID: "1069",
Requestor: "Plath, Sylvia",
RoleAssignments: { },
**Site_ID: "8",**
Status: "In Progress",
Status_ID: "2",
Title: "Design Website Graphics",
Website: "SharePoint" },
length: 1 ]
我在$ scope中还有一个名为网站的对象,目前有13个节点,其中相关的对象记录为:
{
[functions]: ,
__metadata: { },
ID: 8,
Id: 8,
Title: "SharePoint"
}
所以我想显示网站的名称(在SharePoint中称为标题)而不是ID,所以我将此功能添加到控制器:
$scope.getWebsite = function(id){
for(w=0; w<$scope.websites.length; w++){
if($scope.website[w].ID == id){
return $scope.website[w].Title;
} // end if
} // end for
};
对于AgularJS来说还是一个新手,对我来说非常有意义,我会找到匹配并将网站的名称分配给$ scope.getWebsite,这意味着当我把它放在模板中时它会正确显示:
<p>{{getWebsite(thisProject[0].Site_ID)}}</p>
控制台充满了
的13条错误消息(每个网站一条)无法插值
{{getWebsite(thisProject[0].Site_ID}}
。
答案 0 :(得分:1)
看起来你在getWebsite
内有一些拼写错误。在......
if($scope.website[w].ID == id){
return $scope.website[w].Title;
website
属性应为复数。