Ember 观察时未定义选择框
Ember Selection Box undefined on observe
我有一个Ember选择框如下:
{{view "select" class="form-control" content=chooseChannel
optionLabelPath="content.name"
optionValuePath="content.value"
value=selectedChannel
prompt="Please Select"
}}
还有一个函数如下:
watchtype:function(){
console.log(this.get("selectedChannel"));
}.observes('selectedChannel'),
因此,每次用户在选择框中选择一个值时都会触发该函数。
我的问题是函数 returns 未定义,即使它是由变量值的变化触发的。
知道为什么会这样吗?
我发现了问题所在。我从服务器检索的 JSON 没有要绑定的 "value" 字段。因此,当我将值 optionValuePath 绑定到 content.name 时,它起作用了。
我有一个Ember选择框如下:
{{view "select" class="form-control" content=chooseChannel
optionLabelPath="content.name"
optionValuePath="content.value"
value=selectedChannel
prompt="Please Select"
}}
还有一个函数如下:
watchtype:function(){
console.log(this.get("selectedChannel"));
}.observes('selectedChannel'),
因此,每次用户在选择框中选择一个值时都会触发该函数。
我的问题是函数 returns 未定义,即使它是由变量值的变化触发的。
知道为什么会这样吗?
我发现了问题所在。我从服务器检索的 JSON 没有要绑定的 "value" 字段。因此,当我将值 optionValuePath 绑定到 content.name 时,它起作用了。