1

First off, forgive the hard coded table data. I am doing a simple add row type of thing. I'm wondering how to get at the data in the sibling TDs. Should I be using a form? Or something else? basically I just need access to the data that is already in there and move it to another table.

            <tbody data-bind="foreach: Resources">
                <tr>
                    <td data-bind="text: name">
                    </td>
                    <td data-bind="text: type">
                    </td>
                    <td data-bind="text: contact">
                    </td>
                    <td data-bind="text: status">
                    </td>
                    <td>
                        <input type="button" data-bind="click: addResourceToList" value="Add Resource" />
                    </td>
                </tr>
            </tbody>

Here is the start of the code in the model.

    addResourceToList = function () {
        self.ResourcesInPlan.push(new ResourceListModel({ name: this.title }));
    };

Thanks for any advice.

Update: The data was there, but I missed it. I changed to this line.

  self.ResourcesInPlan.push(new ResourceListModel(this.name));

Because I was referencing the model wrong as you can see.

4

1 回答 1

1

看这个例子:

http://knockoutjs.com/documentation/click-binding.html#note_1_passing_a_current_item_as_a_parameter_to_your_handler_function

KO 也会将该项目作为第一个参数发送给函数。

于 2013-06-12T00:21:09.677 回答