簡體   English   中英

如何使用Ember-CLI在ArrayController中獲取Ember-Data值?

[英]How do I fetch Ember-Data Values in an ArrayController using Ember-CLI?

我是新來Ember.js和灰燼,CLI和具有不能去取我的ArrayController具體型號值 ,在這里操縱它的這個相當基本的問題。 我通過ember.js文檔多次閱讀了有關控制器設置和模型顯示的信息

http://emberjs.com/guides/controllers/representing-multiple-models-with-arraycontroller/

但還沒有找到解決方案。

這是我的路線,控制器和模型文件:

    // /routes/sequences.js
import Ember from 'ember';

var SequencesRoute =  Ember.Route.extend({

        model: function() {
                return this.store.find('sequences');
        },
        setupController: function(controller, model) {
                this._super(controller, model);
        }
});


export default SequencesRoute;



// /controllers/sequences.js
import Ember from 'ember';

var SequencesController = Ember.ArrayController.extend({

    init: function() {
                 this._super();
                 this.typeSeq();
    },
    i: 0,
    seqData: function(){
                var seq =  this.get('model.nts');
                return seq;
    }.property('model.nts'),
    len: function(){
                var slen = this.get('seqData');
                return slen.length;
    }.property('seqData'),
    typeSeq: function() {
                var tthis = this;
                var sequence = this.get('seqData');
                var lenn = this.get('len');
                 if (tthis.i <= lenn){
                        console.log(tthis.i);
                        console.log(sequence.substring(tthis.i,tthis.i+1));
                        tthis.i++;     
                        Ember.run.later(function(){
                                   tthis.typeSeq();
                                   }, 200
                        );             
                }
                else{
                        return false;
                }
        }
});

export default SequencesController;


// /models/sequences.js
import DS from 'ember-data';

var Genes = DS.Model.extend({
geneName: DS.attr('string'),
nts: DS.attr('string')
});

Genes.reopenClass({
FIXTURES: [
{
id: 1,
geneName: "Monoamine Oxidase A",
nts: "CTGCAGCGAGCGCGGGAAGCGGGACAGGGCCTAGAGTCACTTCTCCCCGCCCCTGACTGGCCCG"
},
{
id: 2,
geneName: "Monoamine Oxidase B",
nts: "TTTCTGCAGCGAGCGCGGGAAGCGGGACAGGGCCTAGAGTCACTTCTCCCCGC"
}
]
});

export default Genes;

特別是在我的控制器中設置seqData的屬性對我來說還不清楚。 將模型數據放入屬性中到底需要調用什么? 路由器中的setupController方法會不會在ArrayController中設置模型屬性,因此可以通過model.nts進行獲取? 現在,我的ember應用程序將生成,但是在typeSeq函數中設置的var sequence仍未定義。

很高興聽到您的一些答案,或者獲取有關此主題的不錯的教程的鏈接!

1)我相信序列應該是單數,但也許其他方法可行嗎?

return this.store.find('sequence'); 

代替

return this.store.find('sequences');

2)不需要做所有的init / seqData東西,數組控制器的content屬性將自動設置為this.store.find('sequence'); 從路線模型掛鈎中,您可以執行此操作

len: function(){
    var length = [];
    this.get('content').forEach(function(item) {
           length.push(item.get('nts').length);
     });
    return length;
}.property('content'),

暫無
暫無

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

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