Fixed setting list item entity type in SP CRUD sample (#17)

This commit is contained in:
Waldek Mastykarz 2016-09-16 11:33:53 +02:00 committed by GitHub
parent 1a92b8124e
commit 05fcbeda4a
3 changed files with 6 additions and 25 deletions

View File

@ -158,12 +158,7 @@ export default class DataService implements IDataService {
public deleteItem(item: IListItem, webUrl: string, listName: string): ng.IPromise<{}> {
const deferred: ng.IDeferred<{}> = this.$q.defer();
let listItemEntityTypeName: string = undefined;
this.getListItemEntityTypeName(webUrl, listName)
.then((typeName: string): ng.IPromise<ng.IHttpPromiseCallbackArg<string>> => {
listItemEntityTypeName = typeName;
return this.getRequestDigest(webUrl);
})
this.getRequestDigest(webUrl)
.then((requestDigest: string): ng.IPromise<ng.IHttpPromiseCallbackArg<{}>> => {
return this.$http({
url: `${webUrl}/_api/web/lists/getbytitle('${listName}')/items(${item.Id})`,

View File

@ -281,12 +281,7 @@ export default class NoFrameworkCrudWebPart extends BaseClientSideWebPart<INoFra
this.updateStatus('Loading latest items...');
let latestItemId: number = undefined;
let etag: string = undefined;
let listItemEntityTypeName: string = undefined;
this.getListItemEntityTypeName()
.then((listItemType: string): Promise<number> => {
listItemEntityTypeName = listItemType;
return this.getLatestItemId();
})
this.getLatestItemId()
.then((itemId: number): Promise<Response> => {
if (itemId === -1) {
throw new Error('No items found in the list');

View File

@ -97,9 +97,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
.then((listItemEntityTypeName: string): Promise<Response> => {
const body: string = JSON.stringify({
'__metadata': {
'type': 'SP.Data.' +
this.props.listName.charAt(0).toUpperCase() +
this.props.listName.slice(1) + 'ListItem'
'type': listItemEntityTypeName
},
'Title': `Item ${new Date()}`
});
@ -124,7 +122,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
this.setState({
status: 'Error while creating the item: ' + error,
items: []
})
});
});
}
@ -258,9 +256,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
});
const body: string = JSON.stringify({
'__metadata': {
'type': 'SP.Data.' +
this.props.listName.charAt(0).toUpperCase() +
this.props.listName.slice(1) + 'ListItem'
'type': listItemEntityTypeName
},
'Title': `Item ${new Date()}`
});
@ -299,12 +295,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
});
let latestItemId: number = undefined;
let etag: string = undefined;
let listItemEntityTypeName: string = undefined;
this.getListItemEntityTypeName()
.then((listItemType: string): Promise<number> => {
listItemEntityTypeName = listItemType;
return this.getLatestItemId();
})
this.getLatestItemId()
.then((itemId: number): Promise<Response> => {
if (itemId === -1) {
throw new Error('No items found in the list');