Я новичок в Ember JS, это небольшое и простое приложение, в котором пользователь создает набор правил внутри основного представления, каждый отдельный набор правил добавляется внутри основного представления, и каждое представление содержит небольшое представление, в котором пользователь может зарегистрировать правило, а затем каждое правило указано в представлении набора правил, это прекрасно работает, но когда пользователь создает набор правил, правила внутри первого набора правил повторяются в новом представлении набора правил.
Что я делаю?
Примечание. Я не хочу использовать маршруты.
Попробуйте сами, чтобы вы могли видеть, о чем я говорю.
Я буду благодарен за любую помощь
<html>
<head>
<style type="text/css">
#maincontrol {
position:relative;
height:155px;
width:550px;
background-color:#F7C681;
border-radius:15px;
padding-bottom:20px;
}
.container {
position:relative;
padding-top:50px;
width:550px;
}
.ruleset {
position:relative;
height:550px;
width:550px;
background-color:#F7C681;
border-radius:15px;
padding-left:20px;
padding-top:20px;
padding-bottom:20px;
}
</style>
</head>
<body>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.1.0/moment.min.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.1.2/ember.js"></script>
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.3/ember-data.js"></script>
<script type="text/x-handlebars" data-template-name="application-template">
<div id="maincontrol">
<table>
<tr>
<td>Ruleset name:</td><td>{{view Ember.TextField valueBinding="controller.ruleset"}}</td>
</tr>
<tr>
<td>Log:</td><td>{{view Ember.TextArea valueBinding="controller.thelog" rows="5" cols="52"}}</td>
</tr>
<tr>
<td></td><td><button {{action "addPattern" target="controller"}}>Add ruleset</button></td>
</tr>
</table>
<div class="container">
{{#each data in controller}}
{{view Parsertool.PatterncontainerView controller=data }}
{{/each}}
</div>
</div>
</script>
<script type="text/x-handlebars" data-template-name="patterncontainer-template">
<div class="ruleset">
<p>Ruleset: {{controller.name}}</p>
<table>
<tr>
<td>Log:</td><td>{{view Ember.TextArea valueBinding="controller.log" rows="5" cols="52"}}</td>
</tr>
</table>
<br>
<p>Create a rule</p>
{{#view Parsertool.CreateparseView}}
<div>
<table>
<tr>
<td>Name:</td>
<td>{{view Ember.TextField valueBinding="controller.rulename"}}</td>
</tr>
<tr>
<td></td><td><button {{action "addR" target="controller"}}>Add</button></td>
</tr>
</table>
</div>
<p>Rules created:</p>
{{#each pat in controller}}
{{view Parsertool.PatternruleView controller=pat}}
{{/each}}
{{/view}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="patternrule-template">
<table>
<tr>
<td>Name:</td><td>{{controller.rulename}}</td>
</tr>
</table>
</script>
<script>
window.Parsertool = Em.Application.create({});
//################### CONTROLLERS
Parsertool.IndexController = Em.ArrayController.extend({
content:[],
ruleset:"",
thelog:"",
iAm:"IndexController",
actions:{
addPattern:function(){
var t={"name":this.get("ruleset"),
"log":this.get("thelog")
};
this.get("content").pushObject(t);
}
}
});
Parsertool.PatterncontainerController = Em.ArrayController.extend({
content:[],
iAm:"PatterncontainerController",
parentController:Parsertool.IndexController.create(),
});
Parsertool.CreateparseController = Em.ArrayController.extend({
parentController:Parsertool.PatterncontainerController.create(),
content:[],
iAm:"CreateparseController",
rulename:"",
actions:{
addR:function(){
var ru={"rulename":this.get("rulename")
};
this.get("content").pushObject(ru);
}
}
});
//################### VIEWS
Parsertool.IndexView = Ember.View.extend({
templateName:"application-template",
controller:Parsertool.IndexController.create(),
init:function(){
return this._super();
}
});
Parsertool.CreateparseView = Em.View.extend({
controller:Parsertool.CreateparseController.create(),
init:function(){
return this._super();
}
});
Parsertool.PatterncontainerView = Ember.View.extend({
templateName:"patterncontainer-template",
init:function(){
return this._super();
}
});
Parsertool.PatternruleView = Ember.View.extend({
templateName:"patternrule-template"
});
</script>
</body>
</html>
Если я правильно понимаю, я думаю, что это может быть
<p>Rules created:</p>
{{#each pat in controller}}
{{view Parsertool.PatternruleView controller=pat}}
{{/each}}
Разве вы не хотите просматривать #each pat в файле controller.ruleset? В противном случае он просто проходит через все контроллеры.