Tengo la siguiente estructura de ContextualMenu dentro de mi compilación de SPFx Extension con Fluent UI React:
const menuProps: IContextualMenuProps = { items: [ { key: 'Access', itemType: ContextualMenuItemType.Section, sectionProps: { topDivider: true, bottomDivider: true, title: 'Sites you have access to', items: [ { key: 'DynamicValue1.1', text: 'DynamicValue1.2' }, { key: 'DynamicValue2.1', text: 'DynamicValue2.2' }, ], }, }, ], };También realicé una llamada de MS Graph para obtener algunos sitios y equipos de SharePoint.
Ahora me gustaría enviar esas respuestas dinámicas a los menuProps en el lugar correcto.
Básicamente, agregue la matriz dinámica en el objeto de items anidados.
items: [ { key: 'DynamicValue1.1', text: 'DynamicValue1.2' }, { key: 'DynamicValue2.1', text: 'DynamicValue2.2' }, ], ¿Cómo puedo apuntar a ese "objeto"? (Espero entender correctamente y items son un objeto...)
¿Hay que esperar para hacer esto usando array.push() ?
Para hacer que esta biblioteca sea independiente, se vería así:
const obj = { items: [ { key: 'Access', itemType: '', sectionProps: { topDivider: true, bottomDivider: true, title: 'Sites you have access to', items: [ { key: 'DynamicValue1.1', text: 'DynamicValue1.2' }, { key: 'DynamicValue2.1', text: 'DynamicValue2.2' }, ], }, }, ], }; obj.items[0].sectionProps.items.push({ key: 'DynamicValue3.1', text: 'DynamicValue3.2' }) console.log(obj.items[0].sectionProps.items) Tu console.log devolvería esto:
[ { key: 'DynamicValue1.1', text: 'DynamicValue1.2' }, { key: 'DynamicValue2.1', text: 'DynamicValue2.2' }, { key: 'DynamicValue3.1', text: 'DynamicValue3.2' } ] Si puede acceder a menuProps: IContextualMenuProps , simplemente reemplace obj con la variable necesaria.