Fixed setting list item entity type in SP CRUD sample (#17)
This commit is contained in:
parent
1a92b8124e
commit
05fcbeda4a
|
@ -158,12 +158,7 @@ export default class DataService implements IDataService {
|
||||||
public deleteItem(item: IListItem, webUrl: string, listName: string): ng.IPromise<{}> {
|
public deleteItem(item: IListItem, webUrl: string, listName: string): ng.IPromise<{}> {
|
||||||
const deferred: ng.IDeferred<{}> = this.$q.defer();
|
const deferred: ng.IDeferred<{}> = this.$q.defer();
|
||||||
|
|
||||||
let listItemEntityTypeName: string = undefined;
|
this.getRequestDigest(webUrl)
|
||||||
this.getListItemEntityTypeName(webUrl, listName)
|
|
||||||
.then((typeName: string): ng.IPromise<ng.IHttpPromiseCallbackArg<string>> => {
|
|
||||||
listItemEntityTypeName = typeName;
|
|
||||||
return this.getRequestDigest(webUrl);
|
|
||||||
})
|
|
||||||
.then((requestDigest: string): ng.IPromise<ng.IHttpPromiseCallbackArg<{}>> => {
|
.then((requestDigest: string): ng.IPromise<ng.IHttpPromiseCallbackArg<{}>> => {
|
||||||
return this.$http({
|
return this.$http({
|
||||||
url: `${webUrl}/_api/web/lists/getbytitle('${listName}')/items(${item.Id})`,
|
url: `${webUrl}/_api/web/lists/getbytitle('${listName}')/items(${item.Id})`,
|
||||||
|
|
|
@ -281,12 +281,7 @@ export default class NoFrameworkCrudWebPart extends BaseClientSideWebPart<INoFra
|
||||||
this.updateStatus('Loading latest items...');
|
this.updateStatus('Loading latest items...');
|
||||||
let latestItemId: number = undefined;
|
let latestItemId: number = undefined;
|
||||||
let etag: string = undefined;
|
let etag: string = undefined;
|
||||||
let listItemEntityTypeName: string = undefined;
|
this.getLatestItemId()
|
||||||
this.getListItemEntityTypeName()
|
|
||||||
.then((listItemType: string): Promise<number> => {
|
|
||||||
listItemEntityTypeName = listItemType;
|
|
||||||
return this.getLatestItemId();
|
|
||||||
})
|
|
||||||
.then((itemId: number): Promise<Response> => {
|
.then((itemId: number): Promise<Response> => {
|
||||||
if (itemId === -1) {
|
if (itemId === -1) {
|
||||||
throw new Error('No items found in the list');
|
throw new Error('No items found in the list');
|
||||||
|
|
|
@ -97,9 +97,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
|
||||||
.then((listItemEntityTypeName: string): Promise<Response> => {
|
.then((listItemEntityTypeName: string): Promise<Response> => {
|
||||||
const body: string = JSON.stringify({
|
const body: string = JSON.stringify({
|
||||||
'__metadata': {
|
'__metadata': {
|
||||||
'type': 'SP.Data.' +
|
'type': listItemEntityTypeName
|
||||||
this.props.listName.charAt(0).toUpperCase() +
|
|
||||||
this.props.listName.slice(1) + 'ListItem'
|
|
||||||
},
|
},
|
||||||
'Title': `Item ${new Date()}`
|
'Title': `Item ${new Date()}`
|
||||||
});
|
});
|
||||||
|
@ -124,7 +122,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
|
||||||
this.setState({
|
this.setState({
|
||||||
status: 'Error while creating the item: ' + error,
|
status: 'Error while creating the item: ' + error,
|
||||||
items: []
|
items: []
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,9 +256,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
|
||||||
});
|
});
|
||||||
const body: string = JSON.stringify({
|
const body: string = JSON.stringify({
|
||||||
'__metadata': {
|
'__metadata': {
|
||||||
'type': 'SP.Data.' +
|
'type': listItemEntityTypeName
|
||||||
this.props.listName.charAt(0).toUpperCase() +
|
|
||||||
this.props.listName.slice(1) + 'ListItem'
|
|
||||||
},
|
},
|
||||||
'Title': `Item ${new Date()}`
|
'Title': `Item ${new Date()}`
|
||||||
});
|
});
|
||||||
|
@ -299,12 +295,7 @@ export default class ReactCrud extends React.Component<IReactCrudProps, IReactCr
|
||||||
});
|
});
|
||||||
let latestItemId: number = undefined;
|
let latestItemId: number = undefined;
|
||||||
let etag: string = undefined;
|
let etag: string = undefined;
|
||||||
let listItemEntityTypeName: string = undefined;
|
this.getLatestItemId()
|
||||||
this.getListItemEntityTypeName()
|
|
||||||
.then((listItemType: string): Promise<number> => {
|
|
||||||
listItemEntityTypeName = listItemType;
|
|
||||||
return this.getLatestItemId();
|
|
||||||
})
|
|
||||||
.then((itemId: number): Promise<Response> => {
|
.then((itemId: number): Promise<Response> => {
|
||||||
if (itemId === -1) {
|
if (itemId === -1) {
|
||||||
throw new Error('No items found in the list');
|
throw new Error('No items found in the list');
|
||||||
|
|
Loading…
Reference in New Issue