你好,我是aurelia js的新手,我遇到了一个绑定问题,我在一个页面上有两个md-select下拉列表,当表单加载时,它会填充一个商店列表,它的工作方式如下所示
<select md-select="label:Shop" value.two-way="addShopProfile.shopId" change.delegate="getItems(addShopProfile.shopId)">
<option value="" disabled selected>Please select</option>
<option repeat.for="shop of shops" value.bind="shop.id">${shop.name}</option>
</select>您可以看到,我有一个change.delegate="getItems(addShopProfile.shopId)">,因为我想让下面的下拉列表根据商店id为商店装入商品。
<select md-select="label: Items" if.bind="addShopProfile.shopId" value.two-way="addShopProfile.ItemsId">
<option value="" disabled selected>Please select</option>
<option repeat.for="item of Items" value.bind="item.id">${item.name}</option>
</select>现在,只有当我单击选择选项来更改Shop时,才会加载这些项目(这是正确的)。如果商店加载到表单上,则该商店的商品不会显示,除非我点击它。
如何在已加载的商店中绑定要立即加载的商品选择选项,而不必在第一次出现时单击商店选择选项进行更改
发布于 2020-09-13 02:02:02
为了解决这类问题,我通常会在Aurelia提供的attached函数中调用我的函数(在你的例子中)它的getItems(addShopProfile.shopId)。i.e
attached()
{
getItem(id here)
}因此,一旦dom被加载,您的select字段也将加载与您提供的id对应的数据。
https://stackoverflow.com/questions/63795605
复制相似问题