簡體   English   中英

更改內容數組后,Ember.Select視圖未更新

[英]Ember.Select view not updating after changing the content array

我嘗試使用EmberJS更新把手模板,但我想知道如何去做

這是我的JavaScript文件中的代碼段。

App.selectedCoreController = Ember.Object.create({
content: null
});
App.FieldsController = Ember.ArrayController.extend({
fields: [],
active: function() {
    if (App.selectedCoreController.content) {
        console.log(App.selectedCoreController.content)
        var fields =[];
        Ember.RSVP.Promise.cast(Ember.$.getJSON('/ALL/' + App.selectedCoreController.content))
            .then(undefined, function() {
                return null;
            })
            .then(function(response) {
                console.log(response);
                return response.fields.map(function(d){
                    return d.name;
                });
            });
    } else {
        return null;
    }
}.property("App.selectedCoreController.content").cacheable()});
App.fieldsController = App.FieldsController.create();

這是Handlebars腳本的一部分

{{view App.Select contentBinding   =App.arrays.cores
                        selectionBinding = "App.selectedCoreController.content"}}
{{view App.Select contentBinding   = "App.fieldsController.active"}}

激活活動功能后,永遠不會更改關於App.fieldsController.active的Ember.Select的內容

經過深入搜索,我找到了解決方案。

問題在於返回的數組位於Ember.RSVP.Promise中,這就是Ember.Select無法檢測到數組中更改的原因。 動作功能的正確實現如下:

active: function() {
    if (App.selectedCoreController.content) {
        Ember.RSVP.Promise.cast(Ember.$.getJSON('/ALL/' + App.selectedCoreController.content))
            .then(undefined, function() {
                return null;
            })
            .then(function(response) {
                App.FieldsController.fields = response.fields.map(function(d) {
                    return d.name;
                });
            });
        console.log(App.FieldsController.fields);
        return App.FieldsController.fields;        
    } else {
        return null;
    }
}.property("App.selectedCoreController.content").cacheable()

這是一個詳細的解決方案

暫無
暫無

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

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