所以,我从资源选择器中获取选定的项目并尝试将其用于initialSelectionIds
.
但是,在开始使用它时出现此错误,因为它是空的:我也不确定如何selectedValue
进入正确的格式。错误:
appBridgeError: APP::ERROR::INVALID_OPTIONS: `type_error_expected_object` thrown for path: ['initialSelectionIds']['0'] and value: `[]
const handleSelection = (resources) => {
const idsFromResources = resources.selection.map(v => "id:'" + v.id +'\'');
const namesFromResources = resources.selection.map(p => p.title);
selectedValue = JSON.parse(idsFromResources); <Page
title='Allergen Selector'
primaryAction={{
content: 'Select Allergens',
onAction: () => opend(),
}}>
<ResourcePicker
resourceType="Product"
showVariants={true}
open={active}
onSelection={(resources) => handleSelection(resources)}
onCancel={handleToggle}
initialSelectionIds={[selectedValue ] }
/>
</Page>
但是当我使用它时它会起作用:
const productWithAllVariantsSelected = {
id: 'gid://shopify/Product/6337793261759',
};
<ResourcePicker
resourceType="Product"
showVariants={true}
open={active}
onSelection={(resources) => handleSelection(resources)}
onCancel={handleToggle}
initialSelectionIds={[productWithAllVariantsSelected] }
/>