如何在 ember-cli-materialize 中配置 md-select 组件?选项是什么意思?
How do I configure the md-select component in ember-cli-materialize? What do the options mean?
online demo site 上的示例代码给出了以下示例:
{{md-select content=frameworks
value=framework
label="Framework"
prompt="Please choose..."
optionLabelPath="content.value"
optionValuePath="content" class="col s12"}}
frameworks
是 model/route 上的某种数组吗?我试过这样定义框架:frameworks: ["Option 1","Option 2"]
和 frameworks: [{text:"Option 1",value:"1"},{text:""Option 2"",value:"2"}]
但我仍然只得到带有默认占位符的空 select 元素。
optionLabelPath
和 optionValuePath
选项如何工作?
TLDR; 如何在 material select 元素上配置选项(和相关值)来自 ember-cli-material加载插件?
内容是做选项的数组。
organismContent: [
{ value: 'F', display_name: 'Fungi' },
{ value: 'A', display_name: 'Alveolata (alveolates)' },
{ value: 'B', display_name: 'Bryophyta (mosses)' },
]
在模板中你会使用这样的东西
...
content=organismContent // Array to iterate over
optionLabelPath="content.display_name" // user sees this field
optionValuePath="content.value" // user picks this field
value=run.organism // where the user selected value goes to
...
...
content=organismContent // Array to iterate over
optionLabelPath="content.display_name" // user sees this field
xxx // No need value path here
selection=run.organism // user selects the whole object
...
其中 optionValuePath 是绑定到 value=blah 的对象 属性 "value"。如果您使用 selection=blah 而不是 value=blah,它会使用 "display_name" 和 "value" 选择整个对象。第一个用例 (value=) 是当您的对象选择是字符串时,第二个用例 (selection=) 是当您使用外键时(属于)。
export default Ember.Route.extend({
model: function() {
var store = self.get('store');
return Ember.RSVP.hash({
organismContentFromServer: store.find('somemodel', 1) // you can access this via model.organismContentFromServer
});
},
setupController: function(controller, model) {
this._super(controller, model);
controller.setProperties({
organismContent: [], // This property is now accessible in template
});
}
});
将控制器和模型属性绑定到组件
{{analysis/analysis-data <--- This is a component
run=model.run <--- This is a model property
componentorganismContent=organismContent <-- This is a controller property
}}
现在在组件 hbs 中
我可以做 componentorganismContent.length
并且它访问控制器的 organismContent.
或者如果我这样做 {{run}}
它访问模型的钩子 "Run"
如果你得到最后一部分 ember 对你来说会容易得多;)
online demo site 上的示例代码给出了以下示例:
{{md-select content=frameworks
value=framework
label="Framework"
prompt="Please choose..."
optionLabelPath="content.value"
optionValuePath="content" class="col s12"}}
frameworks
是 model/route 上的某种数组吗?我试过这样定义框架:frameworks: ["Option 1","Option 2"]
和 frameworks: [{text:"Option 1",value:"1"},{text:""Option 2"",value:"2"}]
但我仍然只得到带有默认占位符的空 select 元素。
optionLabelPath
和 optionValuePath
选项如何工作?
TLDR; 如何在 material select 元素上配置选项(和相关值)来自 ember-cli-material加载插件?
内容是做选项的数组。
organismContent: [
{ value: 'F', display_name: 'Fungi' },
{ value: 'A', display_name: 'Alveolata (alveolates)' },
{ value: 'B', display_name: 'Bryophyta (mosses)' },
]
在模板中你会使用这样的东西
...
content=organismContent // Array to iterate over
optionLabelPath="content.display_name" // user sees this field
optionValuePath="content.value" // user picks this field
value=run.organism // where the user selected value goes to
...
...
content=organismContent // Array to iterate over
optionLabelPath="content.display_name" // user sees this field
xxx // No need value path here
selection=run.organism // user selects the whole object
...
其中 optionValuePath 是绑定到 value=blah 的对象 属性 "value"。如果您使用 selection=blah 而不是 value=blah,它会使用 "display_name" 和 "value" 选择整个对象。第一个用例 (value=) 是当您的对象选择是字符串时,第二个用例 (selection=) 是当您使用外键时(属于)。
export default Ember.Route.extend({
model: function() {
var store = self.get('store');
return Ember.RSVP.hash({
organismContentFromServer: store.find('somemodel', 1) // you can access this via model.organismContentFromServer
});
},
setupController: function(controller, model) {
this._super(controller, model);
controller.setProperties({
organismContent: [], // This property is now accessible in template
});
}
});
将控制器和模型属性绑定到组件
{{analysis/analysis-data <--- This is a component
run=model.run <--- This is a model property
componentorganismContent=organismContent <-- This is a controller property
}}
现在在组件 hbs 中
我可以做 componentorganismContent.length
并且它访问控制器的 organismContent.
或者如果我这样做 {{run}}
它访问模型的钩子 "Run"
如果你得到最后一部分 ember 对你来说会容易得多;)