sortProperties
奇妙な問題が発生しています。モデルをプロジェクト名でソートしようとしていますが、機能していません。
これが私のものcontroller
です:
App.Model = Ember.Object.extend({
});
//Map appropriate columns
App.Projects = App.Model.extend({
id : null,
projectname : null,
projectdesc : null,
projectbudget : null
});
App.ProjectsController = Ember.ObjectController.extend({
});
App.ProjectsController = Ember.ArrayController.extend({
sortProperties: ['projectname'],
sortAscending: true,
//This function is binded to the searchText value of search box.
filteredContent : function() {
//'i' flag means user can search with either upper case or lower case character
var searchText = this.get('searchText'), regex = new RegExp(searchText, 'i');
return this.get('model').filter(function(item) {
return regex.test(item.projectname);
});
}.property('searchText', 'model')
});
App.ProjectdetailController = Ember.ObjectController.extend({
actions : {
update : function() {
var id = this.get('id');
data = {
projectname : this.get('projectname'),
projectdesc : this.get('projectdesc'),
projectbudget : this.get('projectbudget'),
};
console.log(JSON.stringify(data));
console.log(id);
$.ajax({
type : "POST",
url : "http://pioneerdev.us/users/editProject/" + id,
data : data,
dataType : "json",
success : function(data) {
console.log('success');
//alert('');
}
});
alertify.success("Record Updated");
this.transitionTo('projects');
return false;
}
}
});
//Model to back the Projects template
App.ProjectsRoute = Ember.Route.extend({
model : function() {
return App.Projects.findAll();
}
});
//Model to ProjectDetail view
App.ProjectdetailRoute = Ember.Route.extend({
model : function(params) {
return App.Projects.findBy(params.project_id);
}
});
//methods for the model
App.Projects.reopenClass({
sortProperties: ['projectname'],
findAll : function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
$.getJSON("http://pioneerdev.us/users/getProjects", function(data) {
var result = data.projects.map(function(row) {
return App.Projects.create(row);
});
resolve(result);
}).fail(reject);
});
},
findBy : function(project_id) {
return new Ember.RSVP.Promise(function(resolve, reject) {
var project = App.Projects.create();
$.getJSON("http://ankur.local/users/getProjectById/" + project_id, function(data) {
var result = project.setProperties(data.project);
resolve(result);
}).fail(reject);
});
}
});
テンプレートは次のとおりです。
<script type="text/x-handlebars" id="projects">
<div class="row-fluid">
<div class="span3 offset3">
<div class="row-fluid">
<div class="span10" id="projectlist">
{{input type="text" value=searchText placeholder="Search Your Projects"}}
<ul>
<li>{{#each item in filteredContent}}
{{#link-to 'projectdetail' item}}{{item.projectname}}{{/link-to}}
<br>
{{else}}
<p>Sorry, No Data</p>
{{/each}}
</li>
</ul>
</div>
</div>
<div class="row">
<div class="span5 offset5">{{outlet}}</div>
</div>
</div>
</div>
動機を達成するために何ができますか?私のコードは何か間違っていますか?