Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:31:07+00:00 2026-06-12T05:31:07+00:00

I try to bind a array from another array’s change. but it not work.

  • 0

I try to bind a array from another array’s change. but it not work.

The test.js code like this:

var App = Em.Application.create();

Item = Ember.Object.extend({
    name: null
});

CompareItem = Ember.Object.extend({
    i: null,
    j: null
});

Row = Ember.Object.extend({
    title: null,
    tds: []
});

// see emberjs.com/documention "changes in arrays"
App.Items = Ember.Object.create({
    items: [
    Item.create({name: "01"})
    ,Item.create({name: "02"})
    ,Item.create({name: "03"})
    ],
    compareItems: function() {
    var tdItems = [];
    var items = this.get('items');
    items.forEach(function(left, i, lself) {
        var cprItems = [];
        items.forEach(function(right, j, rself) {
        var compareItem = null;
        compareItem = CompareItem.create({
            i: i,
            j: j
        });
        cprItems[j] = compareItem;
        });
        var row = Row.create({
        title: "["+i+"]",
        tds: cprItems
        });
        tdItems[i] = row;
    });
    return tdItems;
    }.property('items.@each')
});

App.Input = Em.TextField.extend({
    change: function(evt){
    var items = this.value.split(" ");
    items.forEach(function(item, index, all) {
        if ($.trim(item)!=""){
        var it = Item.create({name: item});   
        App.Items.get("items").pushObject(it);
        }
    });
    }
});

App.Table = Em.View.extend({
    templateName: 'bsc-table',
    items: App.Items.get("items")
});

App.EditTr = Em.View.extend({
    compareItems: App.Items.get("compareItems")
});

App.EditTh = Em.View.extend({
});

App.EditTd = Em.View.extend({
});
// Em.run.sync();
var bsctable = App.Table.create();
bsctable.app

The html code like this:

<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]--> <!--[if IE 7 ]>    <html lang="en" class="ie7"> <![endif]--> <!--[if IE 8 ]>    <html lang="en" class="ie8"> <![endif]--> <!--[if IE 9 ]>    <html lang="en" class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title></title>
  <meta name="description" content="">
  <meta name="author" content="">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="shortcut icon" href="/favicon.ico">
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  <link rel="stylesheet" href="css/style.css?v=2">
  <style type="text/css">
  .border-table {
  border: 1px solid #960; border-collapse: collapse;
  }
  .border-table th,td {
  border: 1px solid #960; border-collapse: collapse; padding: 5px;
  }
  .txtInput {width:50px;}
  </style>

  <!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
  <script type="text/x-handlebars" data-template-name="bsc-table">
    <table class="border-table">
      <thead>
    <tr>
      <th>items</th>
      {{#each items}}
      <th>
        {{name}}
      </th>
      {{/each}}
    </tr>
      </thead>
      <tbody>
    {{#view App.EditTr}}
    {{#each compareItems}}
    <tr>
      {{#view App.EditTh itemTrBinding="this"}}
      <th>
        [{{itemTr.title}}]
      </th>
      {{#each itemTr.tds}}
      {{#view App.EditTd itemTdBinding="this"}}
      <td>
        [{{itemTd.i}}]
        [{{itemTd.j}}]
      </td>
      {{/view}}
      {{/each}}
      {{/view}}
    </tr>
    {{/each}}
    {{/view}}
      </tbody>
    </table>
  </script>
</head>
<body>
  <script type="text/x-handlebars">
    {{#view App.Input}}{{/view}}
  </script>

  <script src="js/libs/jquery-1.7.2.min.js"></script>
  <script src="js/libs/ember-0.9.8.1.min.js"></script>
  <script src="js/test.js"></script>
</body>
</html>

then, If you type “04 05 06” into the text field, except that table will be 6*6, but now it is not. like that compareItems is a new one every time, but the table use the old one when the items changed. how to solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:31:08+00:00Added an answer on June 12, 2026 at 5:31 am

    I think you should use array proxy…

    http://docs.emberjs.com/symbols/Ember.ArrayProxy.html

    An ArrayProxy wraps any other object that implements Ember.Array and/or Ember.MutableArray, forwarding all requests. This makes it very useful for a number of binding use cases or other cases where being able to swap out the underlying array is useful.

    A simple example of usage:

    var pets = ['dog', 'cat', 'fish'];
    var ap = Ember.ArrayProxy.create({ content: Ember.A(pets) });
    ap.get('firstObject'); // => 'dog'
    ap.set('content', ['amoeba', 'paramecium']);
    ap.get('firstObject'); // => 'amoeba'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I modified this code from somewhere but I am not sure if I am
This is a really basic question but... I have some code like this var
I am try to bind the dropdowmlist using jquery. But is showing some error.
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
I am trying to bind array of structs to the ToolStripCombobox but with no
The complete code is on https://gist.github.com/1341623 I'd like to sort an index array (or
I have code to retrieve data from a database into a form but it
I'm getting an array of object from the server that I'd like to add
I have this script through which I can change my LDAP password but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.