Ember.js 从组件内调用余烬组件操作
我正在创建一个组件来包装select2选择框。代码如下:Ember.js 从组件内调用余烬组件操作,ember.js,Ember.js,我正在创建一个组件来包装select2选择框。代码如下: App.FixedSelectComponent = Ember.Component.extend({ actions: { change: function(value) { this.set('selectedValue',value); } }, didInsertElement : function(){ this.$("#select1").select2().on("change",
App.FixedSelectComponent = Ember.Component.extend({
actions: {
change: function(value) {
this.set('selectedValue',value);
}
},
didInsertElement : function(){
this.$("#select1").select2().on("change", function(e) {
if ($.isArray(e.val)) {
$.each(e.val, function(index,value) {
console.log("multiple:",value.split('>')[2].split('<')[0]);
// send to change
});
} else {
console.log("single:",e.val.split('>')[2].split('<')[0]);
// send to change
}
});
},
willDestroyElement : function() {
this.$("#select1").select2('destroy');
},
});
App.FixedSelectComponent=Ember.Component.extend({
行动:{
更改:功能(值){
此.set('selectedValue',value);
}
},
didInsertElement:函数(){
此.$(“#select1”).select2().on(“更改”,函数(e){
如果($.isArray(e.val)){
$.each(e.val,函数(索引,值){
console.log(“multiple:”,value.split('>')[2]。split('')[2]。split('请尝试以下操作:
App.FixedSelectComponent = Ember.Component.extend({
change: function(value) {
this.set('selectedValue',value);
}
didInsertElement : function(){
var self = this;
this.$("#select1").select2().on("change", function(e) {
if ($.isArray(e.val)) {
$.each(e.val, function(index,value) {
console.log("multiple:",value.split('>')[2].split('<')[0]);
// send to change
self.change(value); // substitute value by whatever you want to pass
});
} else {
console.log("single:",e.val.split('>')[2].split('<')[0]);
// send to change
self.change(value); // substitute value by whatever you want to pass
}
});
},
willDestroyElement : function() {
this.$("#select1").select2('destroy');
},
});
App.FixedSelectComponent=Ember.Component.extend({
更改:功能(值){
此.set('selectedValue',value);
}
didInsertElement:函数(){
var self=这个;
此.$(“#select1”).select2().on(“更改”,函数(e){
如果($.isArray(e.val)){
$.each(e.val,函数(索引,值){
console.log(“multiple:”,value.split('>')[2]。split(''[2]。split('您可以使用Component.send('actionName')
)
我在一个房间里找到的
检查--'actions'
只是组件上的另一个属性。此
上下文不会引用$中的FixedSelectComponent上下文。每个
都使用send方法,该方法将调用FixedSelectComponent更改方法
参考:
didInsertElement:function(){
var_this=这个;
此.$(“#select1”).select2().on(“更改”,函数(e){
如果($.isArray(e.val)){
$.each(e.val,函数(索引,值){
console.log(“multiple:”,value.split(“>”)[2]。split(“”)[2]。split(“”)[2]。split(“”)[2]。split('这可能解决问题,也可能解决不了问题,但这里没有任何说明它解决了什么问题,或者在哪里应用它。您最好不要使用私有属性/方法,因为它们会在没有任何保证的情况下发生更改。使用Component.send()
请改为。
this._actions['change'].apply(this, value);
this.get('actions').change.call(this, value);
didInsertElement : function(){
var _this = this;
this.$("#select1").select2().on("change", function(e) {
if ($.isArray(e.val)) {
$.each(e.val, function(index,value) {
console.log("multiple:",value.split('>')[2].split('<')[0]);
_this.send('change',value.split('>')[2].split('<')[0]); // send to change
});
} else {
console.log("single:",e.val.split('>')[2].split('<')[0]);
_this.send('change',e.val.split('>')[2].split('<')[0]); // send to change
}
});
}