我有一個非常奇怪的問題,我在我的應用中有兩個觀察者,但只有其中一個正確解僱。我不知道爲什麼會發生這種情況。觀察者未在Ember中被解僱
這裏是有問題的控制器:
App.TwodController = Ember.ArrayController.extend({
//filteredContent : null,
init : function() {
this.set('filteredContent', []);
},
//sortProperties : ['firstname'],
//sortAscending : true,
selectedExperience : null,
filterExperience : function() {
var exp = this.get('selectedExperience.exp');
var filtered = this.get('arrangedContent').filterProperty('experience', exp);
this.set("filteredContent", filtered);
}.observes('selectedExperience'),
experience : [{
exp : "1"
}, {
exp : "2"
}, {
exp : "3"
}, {
exp : "4"
}, {
exp : "5"
}],
selectedDesignation : null,
filterDesignation : function() {
var designation = this.get('selectedDesignation.designation');
var filtered = this.get('arrangedContent').filterProperty('designation', designation);
this.set("filteredContent", filtered);
}.observes('selectedDesignation'),
designations : [{
designation : "Design",
id : 1
}, {
designation : "Writer",
id : 2
}, {
designation : "Script",
id : 3
}, {
designation : "Storyboard",
id : 4
}, {
designation : "Workbook",
id : 5
}],
actions : {
filterExperience : function() {
var experience = this.get('selectedExperience.exp');
var filtered = this.get('content').filterProperty('experience', experience);
this.set("filteredContent", filtered);
},
refresh : function() {
var refresh = this.get('content');
this.set("filteredContent", refresh);
}
},
filteredContent : function() {
var searchText = this.get('searchText'), regex = new RegExp(searchText, 'i');
return this.get('model').filter(function(item) {
var fullname = item.firstname + item.lastname;
return regex.test(fullname);
});
}.property('searchText', 'model')
});
正如你所看到的,我有filterDesignation & filterExperience。但只有filterExperience像預期的那樣工作而不是filterDesignation。
而且這裏是HTML模板對該控制器:
<script type="text/x-handlebars" id="twod">
<div class="row">
<div class="span4">
<img src="/img/2DPipeline.jpg"/>
</div>
<div class="span4">
<h4>2D Roles</h4>
{{view Ember.Select
contentBinding="designations"
optionValuePath="content.id"
optionLabelPath="content.designation"
selectionBinding="selectedDesignation"
prompt="Please Select a Role"}}
{{view Ember.Select
contentBinding="experience"
optionValuePath="content.exp"
optionLabelPath="content.exp"
selectionBinding="selectedExperience"
prompt="Please Select Experience"}}
<br/>
<!-- <button {{action 'filter'}}>Filter By Designation</button>
<button {{action 'filterExperience'}}>Filter By Experience</button>
<button {{action 'refresh'}}>Refresh</button> --> </div>
<div class="span3">
<h4>People with Roles</h4>
{{input type="text" value=searchText placeholder="Search"}}
<div class="row">
<div class="span2">
<ul>
{{#each item in filteredContent}}
<li>{{#link-to 'twoduser' item}}{{item.firstname}} {{item.lastname}} {{/link-to}}</li>
{{/each}}
</ul>
</div>
<div class="row">
<div class="span3">
{{outlet}}
</div>
</div>
</div>
</div>
</div>
</script>
下面是完整的JSBin爲好。
可能是什麼問題?
編輯:「Twod」模板中的搜索框不起作用。任何想法爲什麼?
媽的,從來不知道一個空白會給我這麼多的麻煩。 –
我還有一個問題,值= searchText的搜索框不能在'twod'模板中工作。 –
呵呵,我覺得你在那裏,空白在某個時間點或者另一個時間已經充分發揮了我們的優勢。我會解釋一些上述其他問題。 – Kingpin2k