Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Ember.js 模板未在Ember中绑定模型_Ember.js - Fatal编程技术网

Ember.js 模板未在Ember中绑定模型

Ember.js 模板未在Ember中绑定模型,ember.js,Ember.js,我将尝试在ember中绑定模型、控制器和模板 这是我的js App = Ember.Application.create({}); App.Person = Ember.Object.extend({ firstName: "r", lastName: "issa" }); App.TestingRoute = Ember.Route.extend({ model: function () { return App.Person.create();

我将尝试在ember中绑定模型、控制器和模板 这是我的js

App = Ember.Application.create({});

App.Person = Ember.Object.extend({
    firstName: "r",
    lastName: "issa"
});

App.TestingRoute = Ember.Route.extend({
    model: function () {
        return App.Person.create();
    },
    setupController: function (controller, model) {
        controller.set("model", model);
    }
});

App.TestingController = Ember.ObjectController.extend({
    submitAction: function () {
        alert("My model is :" + this.get("model"));
    }
});
我的模板是:

<script type="text/x-handlebars" data-template-name="application">  
    {{render testing}}
</script>

<script type="text/x-handlebars" data-template-name="testing">

  {{input valueBinding="model.firstName"}}
  {{input valueBinding="model.lastName"}}
    <button {{action submitAction target="controller"}} class="btn btn-success btn-lg">Pseudo Submit</button>
  <p>{{model.firstName}} - {{model.lastName}}</p>

</script>

{{渲染测试}
{{input valueBinding=“model.firstName”}
{{input valueBinding=“model.lastName”}
伪提交
{{model.firstName}-{{model.lastName}


为什么模板和警报重新运行模型中未绑定的模型为空

您的
setupController
model
方法(来自
TestingRoute
的方法)没有被调用。因为控制器是由
渲染
视图辅助对象创建的,而不是由转换创建的

例如,使用以下作品:

模板

<script type="text/x-handlebars" data-template-name="testing">

  {{input valueBinding="model.firstName"}}
  {{input valueBinding="model.lastName"}}
  <button {{action submitAction target="controller"}} class="btn btn-success btn-lg">Pseudo Submit</button>
  <p>{{model.firstName}} - {{model.lastName}}</p>

</script>
这是小提琴

此外,不推荐在控制器中使用操作,而赞成使用
actions:{…}
对象

App = Ember.Application.create({});

App.Router.map(function() {
    this.route('testing', { path: '/' })
});

App.Person = Ember.Object.extend({
    firstName: "r",
    lastName: "issa"
});

App.TestingRoute = Ember.Route.extend({
    model: function () {
        return App.Person.create();
    },
    setupController: function (controller, model) {
        debugger        
        controller.set("model", model);
    }
});

App.TestingController = Ember.ObjectController.extend({
    actions: {
        submitAction: function () {
            alert("My model is :" + this.get("model"));
        }
    }    
});