小编sta*_*key的帖子

Backbone.Marionette:通过CompositeView将数据传递到itemView?

我想知道CompositeView是否/如何将数据传递到其定义的itemView.示例(简化)代码:

var TableView = Backbone.Marionette.CompositeView.extend({
    template: '#table-template',
    itemView: TableRowView,
    itemViewContainer: 'tbody',
});

var TableRowView = Backbone.Marionette.ItemView.extend({
    tagName: 'tr',
    template: '#table-row-template',
    serializeData: function () {
        var data = {
            model: this.model,
            // FIXME This should really only be called once. Pass into TableView, and down into TableRowView?
            // That way, getDisplayColumns can be moved to the collection as well, where it makes more sense for it to belong.
            columns: this.model.getDisplayColumns()
        };
        return data;
    }
});
Run Code Online (Sandbox Code Playgroud)

我正在使用这两个来呈现一个html表.#table-row-template有一些渲染逻辑,用于支持不同类型的"列".这允许我对不同类型的集合/模型使用相同的视图(只要它们遵循API).到目前为止,它运作良好!

但是,正如您在上面所看到的,每次"行"都会调用以获取相同的"列"数据,而实际上我只想将其传递一次,然后用于所有数据.

建议?

谢谢!

marionette

9
推荐指数
1
解决办法
4494
查看次数

PHP4:通过cURL通过HTTPS/POST发送XML?

我编写了一个类/函数,通过PHP4/cURL通过https发送xml,只是想知道这是否是正确的方法,或者是否有更好的方法.

请注意,PHP5目前不是一个选项.

/**
 * Send XML via http(s) post
 *
 * curl --header "Content-Type: text/xml" --data "<?xml version="1.0"?>...." http://www.foo.com/
 *
 */
function sendXmlOverPost($url, $xml) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);

  // For xml, change the content-type.
  curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));

  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned
  if(CurlHelper::checkHttpsURL($url)) { 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  }

  // Send to remote and return data to caller.
  $result = curl_exec($ch);
  curl_close($ch); …
Run Code Online (Sandbox Code Playgroud)

php xml https curl php4

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

curl ×1

https ×1

marionette ×1

php ×1

php4 ×1

xml ×1