从ViewModel访问$ parent

时间:2015-06-01 16:58:08

标签: javascript jquery knockout.js

此代码只是我想要完成的一般示例

父视图模型

TextView

子视图模型

resultList

如何让public View getView(int position, View convertView, ViewGroup parent) { // Try following ViewHolder pattern TextView textView = (TextView) convertView.findViewById(R.id.textView1); Medico med = resultList.get(position); textView.setText(med!=null?med.getNombre() : "-Not Available-"); } @Override public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { resultList.clear(); for (Medico medico : medicos) { // Although I am not sure where are you getting searchIds ?? if (medico.getNombre().contains(searchsds)) { //This is where Im suposed to do something but I dont know what to use to fill the ListView resultList.add(medicos.get(i)); } } mAdapter.notifyDataChanged(); } 工作?

1 个答案:

答案 0 :(得分:2)

当你推新孩子时,将父视图模型传递给孩子的视图模型。

var customerViewModel = function(){
    var self = this;
    self.Images = ko.observableArray([]);

    self.NotifyUser = function(){
        alert('Success');
    };

    self.Images.push(new imageViewModel({foo:'bar'}, self));
};

var imageViewModel = function(item, $parent){
    var self = this;

    self.Rename = function(filePath){
        self.src(filePath);
        $parent.NotifyUser();
    };
};