当前位置: 动力学知识库 > 问答 > 编程问答 >

knockout.js - I have two select list with knockout bindding,but when i change view model's value,the select don't update correctly

问题描述:

I have two select list . And I use ko.utils.arrayFilter method to change my select list.

Everything is good when i use it to do "Add Field" or "Remove Field".

But when i changed the viewmodel,then i click the "Add Field" or "Remove Field" the select list won't update correctly.

 self.test = function(){

var idx = self.rightSeleted();

var selectedField = $.grep(self.availableFields(), function(n, i){

return n.FieldNameId == idx;

});

debugger;

var currentValue = selectedField[0].IsAsc();

};

my sample code is in here http://jsfiddle.net/knupA/

Did i do something wrong when bindding select list ?!

Thanks~

网友答案:

I've updated your jsFiddle, and it seems to work. I changed your method to select from the arrays to use the Knockout method, and I removed your test method, as that was being called when nothing in the right dropdown was selected, so was blowing up.

var selectedField = ko.utils.arrayFirst(self.availableFields(), function(item){
                return item.FieldNameId == idx;
            });
分享给朋友:
您可能感兴趣的文章:
随机阅读: