升级emberjs脚本以支持最新版本

时间:2016-04-29 13:56:04

标签: javascript ember.js ember-cli

我正在使用

  

Emberjs:v1.8.0

我有以下简单的代码

<html>
   <head>
      <title>Important data</title>
      <script src="/handlebars.min.js"></script>
      <script src="/jquery-2.1.3.min.js"></script>
      <script src="/ember.min.js"></script>
      <script src="/ember-template-compiler.js"></script>
      <script src="/ember.debug.js"></script>
      <script src="/ember-data.js"></script>
   </head>
   <body>
      <script type="text/x-handlebars">
         {{view App.View contentBinding="model"}}
      </script>

      <script type="text/x-handlebars" data-template-name="index">
         {{#if view.isShowVisible}}
Name         : <font color='blue'>{{view.content.Name}}</font><br>
City         : <font color='blue'>{{view.content.City}}</font><br>
State        : <font color='blue'>{{view.content.State}}</font><br>
            <button {{action "importantdata" target="view"}}>Edit</button>

          {{else}}
Name         : {{input type="text" value=view.content.Name}}<br>
City         : {{input type="text" value=view.content.City}}<br>
State        : {{input type="text" value=view.content.State}}<br>
            <button {{action "importantdata" target="view"}}>Done</button>
         {{/if}}
      </script>

      <script type="text/javascript">
         App = Ember.Application.create();
         App.ApplicationRoute = Ember.Route.extend({
            model: function() {
               return [{otherdata:''}];

            }
         });

         App.View = Ember.View.extend({
            templateName: 'index',
            isShowVisible: true,
            actions: {
               importantdata: function(){
                  this.toggleProperty('isShowVisible');
               }
            }
        });

      </script>
   </body>
</html>

此脚本中使用的emberjs版本似乎已过时。 而且我听说最新版本的emberjs(v2.4.x)正在以完全不同的方式工作。

我想升级脚本以支持最新版本的emberjs。

对我有什么帮助吗?

我需要花费很多时间来学习最新版本的emberjs。

非常感谢,如果有人能为我提供快速解决方案。

为了使上述脚本支持最新版本的emberj,我需要做些哪些更改?

1 个答案:

答案 0 :(得分:1)

是的,这可以通过简单的方式完成。你可以使用最新的ember的cdns而不是在这里查看你可以使用索引控制器。由于视图已弃用,您可以使用组件而不是以下视图:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Important Data</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.5.1/ember-template-compiler.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.5.1/ember.debug.js"></script>
</head>

<body>
    <script type="text/x-handlebars" id- "application">
        {{outlet}}
    </script>

    <script type="text/x-handlebars" data-template-name="index">
        {{#if isShowVisible}} Name :
        <font color='blue'>{{Name}}</font>
        <br> City :
        <font color='blue'>{{City}}</font>
        <br> State :
        <font color='blue'>{{State}}</font>
        <br>
        <button {{action "importantdata"}}>Edit</button>
        {{else}} Name : {{input type="text" value=Name}}
        <br> City : {{input type="text" value=City}}
        <br> State : {{input type="text" value=State}}
        <br>
        <button {{action "importantdata"}}>Done</button>
        {{/if}}
    </script>
    <script type="text/javascript">
    App = Ember.Application.create();
    App.ApplicationRoute = Ember.Route.extend({
        model: function() {
            return [{
                otherdata: ''
            }];

        }
    });

    App.IndexController = Ember.Controller.extend({
        isShowVisible: true,
        actions: {
            importantdata: function() {
                this.toggleProperty('isShowVisible');
            }
        }

    });
    </script>
</body>

</html>

Here is the JSBin link

相关问题