Ember.js emberjs动态选择值绑定与ajax内容绑定
对于emberjs,我使用Em.Select来显示由通过AJAX检索的JSON填充的选项列表Ember.js emberjs动态选择值绑定与ajax内容绑定,ember.js,Ember.js,对于emberjs,我使用Em.Select来显示由通过AJAX检索的JSON填充的选项列表 {{view Em.Select valueBinding="profile" contentBinding="App.profiles" selectionBinding="profile" optionValuePath="content.id" optionLabelPath=&
{{view Em.Select
valueBinding="profile"
contentBinding="App.profiles"
selectionBinding="profile"
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="Please select a profile"}}
当在创建表单中使用时,它会按预期工作,但是在编辑表单中,该值不会自动被选中
这会导致问题,因为我有一个由3个选择输入组成的链,它们依赖于预览列表中选择的选项
有人能解释一下在JSON列表填充之前如何阻止选项选择吗
解决了的:
谢谢你的帮助。我最终实现它的方法是将select视图包装到if语句中,如下所示:
{{#if App.Profiles}}
{{view Em.Select
valueBinding="profile"
contentBinding="App.profiles"
selectionBinding="profile"
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="Please select a profile"}}
{{/if}}
kroofy建议我将其封装在一个观察到isLoaded属性的if语句中,但由于我的profiles对象没有isLoaded属性,所以我尝试检查App.profiles,结果成功了。可能您可以将其封装在一个条件语句中。因此,它仅在加载配置文件时显示Select
{{#if App.profiles.isLoaded}}
{{view Em.Select
valueBinding="profile"
contentBinding="App.profiles"
selectionBinding="profile"
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="Please select a profile"}}
{{/if}}
或者您只需要将id添加到valueBinding
valueBinding="profile.id"
我看不到在select,typo上定义了任何
selectionBinding
?是的,那是一个打字错误,我无意中从我的创建模板复制了它。用适当的选择示例更新了问题。