添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to sold a small error in my SPFx Project. I understand the problem, but I can't find any solution.

 <DefaultButton className={styles.button} onClick={() => this.addListItems(this.state.data, this.state.selectedDepartmentOptions)}> Eintragen </DefaultButton>
 private addListItems = (user: MicrosoftGraph.User,  selectedDepartmentOptions: IDropdownOption[]): void =>  {
const { selectedRubrikOptions } = this.state;
const departmentKey = user.department;
var isTerminvergabeChecked = (document.getElementById('terminvergabe') as HTMLInputElement | null).checked;
var isHotlineChecked = (document.getElementById('hotline') as HTMLInputElement | null).checked;
let selectedDepartmentText = "";
for (let i = 0; i < selectedDepartmentOptions.length; i++) {
  const option = selectedDepartmentOptions[i];
  console.log(selectedDepartmentOptions[i]);
  if (option.key === departmentKey) {
    selectedDepartmentText = option.text;
    break;
if(selectedRubrikOptions === ""){
  alert('Bitte das Pflichtfeld beachten!');
}else{
  sp.web.lists.getByTitle('Laufkundschaft')
  .items.add({
    'Rubrik': selectedRubrikOptions,
    'Au_x00df_enstellen': selectedDepartmentText,
    'Terminvergabe': isTerminvergabeChecked,
    'Hotline': isHotlineChecked,
  .then(()=> alert("Die Daten wurden erfolgreich gespeichert!"));

I know, the selectedDepartmentOptions is a string, the IDropdownOption[] is an array. I need this array, because of for loop in "addListitems" Method. But I have defined the IDropdownOption as string. I understand a problem, but I do not find any solution. Anyone some idea?

Thank you!

If you have defined selectedDepartmentOptions as string in initial state, change it to IDropdownOption[]. – Ganesh Sanap - Microsoft MVP Feb 15 at 12:49

You need to change your first line to the following.

<DefaultButton
    className={styles.button}
    onClick={() => this.addListItems(this.state.data,
        { key: this.state.selectedDepartmentOptions, text: this.state.selectedDepartmentOptions } as IDropdownOption
    )}> Eintragen </DefaultButton>

To explain behind this, you need to convert to a direct array, then add an object inside with JSON schema that is required to form IDropdownOption.

Thanks for contributing an answer to SharePoint Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.