簡體   English   中英

ember獲取當前組件值

[英]ember get current component value

我有一個拖放布局應用程序組件。 在這一點上,用戶按保存,我想在控制器中獲取組件值並將其存儲。 (我正在使用Ember CLI)並且不知道如何將組件數據放入控制器。 看到過類似的需求嗎?

控制器應用:

save: function(){
  var newName= this.store.createRecord('layout', {
    title: this.get('title')
  });

  newName.save();

  alert('saved');

  this.transitionToRoute('index');

}

零件:

 Setupgridster: function(){
    Ember.$(".gridster ul").gridster({
      widget_base_dimensions: [359, 232],
      widget_margins: [5, 5],
      helper: 'clone',
      resize: {
        enabled: true,
        max_size: [3, 3],
        min_size: [1, 1],
        stop: function (e, ui, $widget) {
          var widget_base_dimensions = this.serialize($widget)[0];
        }
      },
      serialize_params: function($w, wgd) {
          return {
            col: wgd.col,
            row: wgd.row,
            size_x: wgd.size_x,
            size_y: wgd.size_y
          };
      }
    }).data('gridster');
  }.on("didInsertElement")
});

您應該使用組件的JavaScript(位於app/components/your-component.js如果您使用的是Ember-CLI)來實現保存,而不是使用ApplicationController 這樣,組件的功能將由組件本身封裝。

// app/components/your-component.js
export default Ember.Component.extend({
  actions: {
    showConfirmation: function() {
        var store = this.get('store');
        var newName = store.createRecord('layout', {
            title: this.get('title')
        });

        newName.save().then(function(newTaskSaved){
            alert('saved');        
        });            

        this.transitionToRoute('index');
    }
  }
});

在模板中,您可以傳入標題和數據存儲:

{{your-component title=title store=store}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM