根据FAQ section in react-hook-form official website,应使用defaultValues用预先填充的数据初始化表单。但是,我调用API来获取初始数据,并且由于异步调用而导致初始化失败。
是否有更好或正确的初始化方法?
class ItemDetailView(DetailView):
model = Item
template_name = "product.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
related_items = Item.objects.filter(category=self.object.category).order_by('category')
context['related_items'] = related_items
print(related_items)
return context