Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么可以';我不能在没有错误的情况下更改这个模型吗?_Javascript_Html_Model View Controller_Ember.js_Handlebars.js - Fatal编程技术网

Javascript 为什么可以';我不能在没有错误的情况下更改这个模型吗?

Javascript 为什么可以';我不能在没有错误的情况下更改这个模型吗?,javascript,html,model-view-controller,ember.js,handlebars.js,Javascript,Html,Model View Controller,Ember.js,Handlebars.js,我正在编写一个ember应用程序,它有一个设置模型,我用它来绕过路由,因为我想要一个url。但是,我得到了这个错误: Error: Cannot perform operations on a Metamorph that is not in the DOM. 当我更改模型中的任何数据时。我对余烬还比较陌生,但从我读到的资料来看,你应该可以很好地改变一个模型。这是我的html文件: <script type="text/x-handlebars" data-template-name="

我正在编写一个ember应用程序,它有一个设置模型,我用它来绕过路由,因为我想要一个url。但是,我得到了这个错误:

Error: Cannot perform operations on a Metamorph that is not in the DOM.
当我更改模型中的任何数据时。我对余烬还比较陌生,但从我读到的资料来看,你应该可以很好地改变一个模型。这是我的html文件:

<script type="text/x-handlebars" data-template-name="index">    
<div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container">
                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                </a>
                <a class="brand" href="#"><img src="./img/MySpending.png"></a>
                <div class="nav-collapse">
                        <ul id="navWrapper" class="nav">
                   {{#if model.isIndex}}
                    {{partial "indexNav"}}
                   {{/if}}
                   {{#if model.isMonthly}}
                    {{partial "monthlyNav"}}
                   {{/if}}
                   {{#if model.isYearly}}
                    {{partial "yearlyNav"}}
                   {{/if}}
                </ul>
                </div>
            <div class='navbar_form pull-right'></div>
        </div>
        </div>
</div>
<div id="bodyWrapper" class="container" style="padding-top:60px;">
    {{#if model.isIndex}}
    {{partial "indexPage"}}
    {{/if}}
    {{#if model.isMonthly}}
    {{partial "monthlyPage"}}
    {{/if}}
    {{#if model.isYearly}}
    {{partial "yearlyPage"}}
    {{/if}}
</div>
{{outlet}}

因此,我不确定错误在哪里,但如果有人能提供帮助,我将不胜感激。

您使用的是哪个余烬版本?我在ember 1.2和1.3中试用过,您的示例运行良好。

您的方法中存在一个基本错误。您的路由/控制器旨在为您处理模型,因此,通过在这些对象之外声明您的模型,您为自己做了更多的工作,并导致了潜在的麻烦

我看不到你的“goTo”函数在哪里被调用(我假设它们在部分中,但是如果它们在HTML中,我错过了,那就是我的错)。但以下是如何引用它们:

App.SettingsController = Ember.ObjectController.extend({
    actions:{
        goToMonthly:function(){
            this.set('isIndex', false);
            this.set('isMonthly', true);
            this.set('isYearly', false);
        },
        //Other functions go here
    }
});
然后在html中,使用手柄调用以下操作:

<a {{action 'goToMonthly'}}> Click this to run the action </a>
单击此按钮以运行操作
<a {{action 'goToMonthly'}}> Click this to run the action </a>